Scrape HTML elements
The /scrape endpoint extracts structured data from specific elements on a webpage, returning details such as element dimensions and inner HTML.
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-rendering/scrape' \  -H 'Authorization: Bearer <apiToken>' \  -H 'Content-Type: application/json' \  -d '{  "url": "https://example.com/",  "elements": [{    "selector": "h1"  },  {    "selector": "a"  }]}{  "success": true,  "result": [    {      "results": [        {          "attributes": [],          "height": 39,          "html": "Example Domain",          "left": 100,          "text": "Example Domain",          "top": 133.4375,          "width": 600        }      ],      "selector": "h1"    },    {      "results": [        {          "attributes": [            { "name": "href", "value": "https://www.iana.org/domains/example" }          ],          "height": 20,          "html": "More information...",          "left": 100,          "text": "More information...",          "top": 249.875,          "width": 142        }      ],      "selector": "a"    }  ]}url(string) - The webpage to extract data from.elements(object) - Defines the elements to extract from the page.selectors(array of strings) - List of CSS selectors identifying elements to scrape (e.g.,"h1",".article").
results(array of objects) - Contains extracted data for each selector.selector(string) - The CSS selector used.results(array of objects) - List of extracted elements matching the selector.text(string) - Inner text of the element.html(string) - Inner HTML of the element.attributes(array of objects) - List of extracted attributes such ashreffor links.height,width,top,left(number) - Position and dimensions of the element.