웹 캡처 및 변환 도구

Node.js를 사용한 고급 스크린 샷 기능

Node.js API

GrabzIt의 API는 매우 커스터마이징이 가능합니다. 유용한 두 가지 기능은 GrabzIt Node.js API 스크린 샷을 생성하고 컨텐츠를 캡처 할 때 기존 스크린 샷의 상태를 확인하고 GrabzIt에서 전송 한 쿠키를 사용자 정의합니다.

스크린 샷 상태

스크린 샷 또는 캡처 상태를 확인하려면 get_status 이 메소드는 캡처가 여전히 처리되고 있는지, 캐시되었는지 또는 만료되었는지를 나타내는 상태 오브젝트를 리턴합니다.

var grabzit = require('grabzit');

var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret");

client.get_status(screenShotId, function(error, status){
    if (status.processing){
        //screenshot has not yet been processed
    }

    if (status.cached){
        //screenshot is still cached by GrabzIt
    }

    if (status.expired){
        //screenshot is no longer on GrabzIt
        //Perhaps output status message?
    }
});

Cookies

많은 웹 사이트 기능은 쿠키를 통해 제어됩니다. GrabzIt은 아래와 같이 쿠키 방법을 사용하여 사용자 정의 쿠키를 설정할 수 있습니다.

var grabzit = require('grabzit');

var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret");

//gets an array of cookies for google.com
client.get_cookies("google.com", function(error, cookies){
});

//sets a cookie for the google.com domain
client.set_cookie("MyCookie", "google.com", {"value":"Any Value You Like"});

//deletes the previously set cookie
client.delete_cookie("MyCookie", "google.com");

다운로드하지 않고 캡처 표시

권장되는 캡처는 사용하기 전에 웹 서버에 다운로드됩니다. 웹 서버에 먼저 다운로드하지 않고도 사용자의 브라우저에 모든 유형의 캡처를 표시 할 수 있습니다.

이렇게하려면 캡처가 완료되면 oncomplete 함수의 반환 된 캡처 바이트를 보낼 수 있습니다. save_to 방법 응답과 함께 올바른 마임 유형. 이것에 대한 예 url_to_image 방법은 아래에 나와 있지만 모든 변환 방법과 함께 작동합니다.

var grabzit = require('grabzit');

var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret");

client.url_to_image("https://www.tesla.com");
client.save_to(null, function(error, data){
    response.writeHead(200, {"Content-Type":"image/jpeg"});
    response.write(data);
    response.end();
});