DocumentationAPI DetailsScrape URLResponse Selector

Response Selector

This example shows how to use the responseSelector option to reduce the amount of content that is returned by the API. The option supports both CSS selectors and XPath queries.

To use response selector filtering, simply set the responseSelector parameter to any valid CSS selector or XPath query. The results will be filtered and wrapped in a <scrapi> root element to simplify parsing.

Example Request

POST https://api.scrapi.tech/v1/scrape

Example For CSS

{
  "url": "https://deventerprise.com",
  "useBrowser": false,
  "responseSelector": ".title h2"
}

Example For XPath

{
  "url": "https://deventerprise.com",
  "useBrowser": false,
  "responseSelector": "//div[@class='title']/h2"
}

Example Responses

The above request will result in the following content in the response (HTML or in the content property for JSON).

<scrapi>
<h2>
  DevEnterprise Software Limited
  <p>
    DevEnterprise provides custom software solutions for companies and individuals using enterprise level development techniques and services.
  </p>
</h2>
</scrapi>

Note how the HTML is wrapped in a <scrapi> root tag to ensure the response is still valid HTML and will work with HTML/XML parsers for further processing.

When combined with Markdown Responses then there will be no extra content.

## DevEnterprise Software Limited
DevEnterprise provides custom software solutions for companies and individuals using enterprise level development techniques and services.

Errors

If you have supplied an invalid CSS selector or XPath query then the full content will be returned with an item in the errorMessages property (or X-ScrAPI-ErrorMessages header if you are not using the JSON response format) indicating the problem with your selector.

Testing

If you want to test this request or a variation of it, head to the Playground or the OpenAPI page.