JavaScript 渲染
Last updated
Was this helpful?
Last updated
Was this helpful?
我們提供完整的解決方案,讓您免於設置代理、瀏覽器指紋、無頭瀏覽器等。只需在標題中設置渲染類型,你就會收到一個渲染的結果。
您可以選擇以下兩種渲染類型:
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
在這個示例中,我們將渲染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 渲染,請設置為js_render=true,我們將使用瀏覽器來請求。
啟用 JavaScript 渲染產生的消耗高於未開啟,且速度會變慢。
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