Common Issues with CSS Selectors

One of the most common issues users encounter when working with CSS Selectors in web scraping is improper encoding. CSS Selectors need to be correctly encoded to be recognized and processed by the API.

You can use ZenRows’ Builder or an online tool to properly encode your CSS Selectors before sending them in a request.

Example of Using a CSS Selector

Let’s say you want to extract content from the .my-class CSS selector and store it in a property named test. You would encode the selector and include it in your request like this:

curl "https://api.zenrows.com/v1/?apikey=YOUR_ZENROWS_API_KEY&url=YOUR_URL&css_extractor=%257B%2522test%2522%253A%2520%2522.my-class%2522%257D"

Troubleshooting CSS Selector Issues

If you’re still getting empty responses or the parser reports an error:

  1. Check the Raw HTML: Request the plain HTML to see if the content served by the website differs from what you see in your browser. Some websites serve different content based on the user’s location, device, or other factors.

  2. Verify the Selector: Ensure the selector you’re using is correct by testing it in your browser’s Developer Tools (e.g., using Chrome’s Console with document.querySelectorAll(".my-class")).

  3. Review the Documentation: Refer to the ZenRows documentation for detailed information on using CSS Selectors with the API.

If the HTML looks correct, the selector works in the browser, but the parser still fails, contact us, and we’ll help you troubleshoot the issue.