Skip to main content

Web scraping with Javascript rendering

Getting started

Simply send a GET request to http://chrome-v2.browsercloud.io with two query string parameters and the API will return the HTML response:

curl 'https://chrome-v2.browsercloud.io/content?token=API_TOKEN&url=https://site.com'
ParameterAvailable valuesDescription
urlstring, required. Example : https://browsercloud.iosite URL you would like to scrape
tokenstring, required

Proxies & GEO targeting

Our residential proxy pool includes over 70 million IPs from 195 countries from over dozens of ISPs and should be sufficient for the vast majority of scraping jobs.

Proxy behavior is set by parameters proxy and proxyCountry

curl --location 'https://chrome-v2.browsercloud.io/content?token=API_TOKEN&proxy=datacenter&proxyCountry=GB&url=https://api.myip.com'
ParameterAvailable valuesDescription
proxy1) datacenter - datacenter proxy pool with 70mln of fast proxies
2) residential - premium proxy pool for a few particularly difficult to scrape sites
3) omit parameter to use direct connection from our servers
Proxy pool type
proxyCountryparameter works with proxy parameter

1) two-letter country ISO code. Example: US, CA, GB, DE and more
2) omit parameter or set ALL for global rotating
Proxy geo targeting

Wait for Element when rendering

If a rendered request is a bit slow and the page stabilizes before the request is satisfied, it can fool the API into thinking the page has finished rendering.

To cope with this, you can tell the API to wait for a dom element (selector) to appear on the page when rendering. You just need to send the wait-for parameter, passing a URL-encoded jQuery selector.

The API will then wait for this to appear on the page before returning results.

curl 'https://chrome-v2.browsercloud.io/content?token=API_TOKEN&url=https://site.com&wait-for=%23ajax-content'
ParameterAvailable valuesDescription
wait-forstring, Example: %23ajax-content (%23 is # symbol)URL-encoded selector. Requires JS rendering

Javascript execution

You can pass your custom Javascript code to run in the browser context using js_snippet param, and it will be executed after the page load will finish.

Custom javascript can be used for interaction with a page, like scrolling, pressing a button, etc.

curl -X POST \
https://chrome-v2.browsercloud.io/content?token=API_TOKEN \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-d '
{
"url": "https://browsercloud.io/doc-examples/content.html",
"addScriptTag" : [
{
"content" : "let node = document.querySelector(\"#header-2\"); node.textContent = \"My custom JS did it!\""
}
]
}'

Additional parameters

Example with all available JSON options

curl -X POST \
https://chrome-v2.browsercloud.io/content?token=API_TOKEN \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-d '
{
"url": "https://browsercloud.io/doc-examples/content.html",
"addScriptTag" : [
{
"content" : "let node = document.querySelector(\"#header-2\"); node.textContent = \"My custom JS did it!\""
}
],
"setJavaScriptEnabled" : true,
"waitFor" : "#delayed",
"userAgent" : "Mozilla/5.0 (iPhone; CPU iPhone OS 13_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.2 Mobile/15E148 Safari/604.1",
"rejectResourceTypes" : ["image"],
"authenticate" : {
"username" : "test",
"password" : "test"
},
"cookies" : [
{
"name" : "session",
"value" : "session-value",
"domain" : "browsercloud.io"
}
]
}'
ParametersAvailable valuesDescription
urlstringURL for web scraping
setJavaScriptEnabledtrue(default), false - javascript renderingJavascript rendering
waitForstringScript waits certain DOM element to be rendered
addScriptTag.contentstring - js codeAdds custom <script> tag to the page
userAgentstringsets custom UserAgent for a web scraper
rejectResourceTypesstring: 'document','stylesheet','image','media', 'font','script','texttrack','xhr', 'fetch','eventsource','websocket','manifest','other'Blocks unnecessary resource type to boost page load
authenticateusername, password: stringBasic auth
cookiesstringCustom cookies (for example: auth session)