CSS Selectors Do Not Work or "Parser is Not Valid"
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:
Troubleshooting CSS Selector Issues
If you’re still getting empty responses or the parser reports an error:
-
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.
-
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")
). -
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.