JavaScript 渲染

我們提供完整的解決方案,讓您免於設置代理、瀏覽器指紋、無頭瀏覽器等。只需在標題中設置渲染類型,你就會收到一個渲染的結果。

渲染類型


您可以選擇以下兩種渲染類型:

  • png(可保存為PNG的原始字節)

  • html(已渲染頁面的HTML)

接收 HTML 格式的呈現頁面內容

curl --request POST --url https://unlocker-api.lunaproxy.com/request --header "Authorization: Bearer token" --header "content-type: application/json" --data "{\"url\":\"https://www.google.com/\",\"type\":\"html\",\"js_render\":\"False\"}" > google.html

抓取網站的HTML


在這個示例中,我們將渲染YouTube的主頁,並抓取頁面內容。通常情況下,如果使用了通用抓取API而不使用Javascript渲染,則YouTube的主頁樣式如下:

啟用Javascript渲染,並返回渲染後的頁面的HTML:

curl --request POST --url https://unlocker-api.lunaproxy.com/request --header "Authorization: Bearer token" --header "content-type: application/json" --data "{\"url\":\"https://www.google.com/\",\"type\":\"html\",\"js_render\":\"True\"}" > google.html

在瀏覽器中打開的HTML文件應該如下所示:

以 PNG 格式接收呈現的頁面內容

響應將包含可保存為 PNG 格式的圖像的原始字節。

curl --request POST --url https://unlocker-api.lunaproxy.com/request --header "Authorization: Bearer token" --header "content-type: application/json" --data "{\"url\":\"https://www.google.com/\",\"type\":\"png\",\"js_render\":\"True\"}" > google.png

可以保存為PNG格式,並如下方示例打開:

啟用JavaScript 呈現


要激活 JavaScript 渲染,請設置為js_render=true,我們將使用瀏覽器來請求。

curl --request POST --url 
https://unlocker-api.lunaproxy.com/request
 --header "Authorization: Bearer token" --header "content-type: application/json" --data "{\"url\":\"
https://www.google.com/\",\"type\":\"png\",\"js_render\":\"True\"}"
 > google.png

Last updated

Was this helpful?