How to remove any element from the HTML response

Sometimes you may need to remove specific HTML elements from the page’s content, either to get cleaner results for your data extraction rules, or to simply delete unnecessary content from your response.

To achieve that using ScrapingBee, you can use aJavaScript Scenario, with an evaluate instruction and execute this custom JS code:

document.querySelectorAll("ELEMENT-CSS-SELECTOR").forEach(function(e){e.remove();});​

For example, to remove all of the

{"instructions": [{"evaluate": 'document.querySelectorAll("style").forEach(function(e){e.remove();});'}]}

Go back to tutorials

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *