Wait for CSS selector
How to improve web scraper performance and wait for the full page load
Waiting for CSS selector
Generally, our system waits until the entire page load from the networking perspective. It means that the result will be returned right after the networking is performed.
Still, in some cases, a web scraper may require waiting for a particular DOM element appearance. This DOM element may appear in the HTML before and after the entire page load. So, with waiting for CSS selector feature, it's possible to decrease the ScrapingAnt API response time or make a delay after the whole page load to wait for the DOM element.
wait_for_selector parameter is specified, the ScrapingAnt service will no longer wait until the entire page load but wait for the desired DOM element appearance instead.
For example, with waiting for the following element to appear in HTML response:
Your request will have the following additional parameter:
Don't forget to urlencode
wait_for_selector parameter value
How to create a CSS selector?
Check out CSS selectors cheat sheet and CSS Selector Tester to prepare your CSS selector.
Also, the most common selectors can be found below:
|*||*||Selects all elements|
|[attribute]||[age]||Selects all elements with age attribute|
|[attribute=value]||[age=50]||Selects all elements with age=50 attribute|
|[attribute~=value]||[color~=cyan]||Selects all elements with color attribute containing the word “cyan”|
|[attribute*=value]||a[href*=”voted”]||Selects all |
|.class||.h1||Selects all elements in the HTML file with the class “h1”|
|.class1.class2||.postition1.position2||Selects all elements that have both “position1” and “position2” in its class attribute|
|.class1 .class2||.position1 .position2||Selects all parent elements that contain position1 as the attribute and with children as position2 attribute|
|:default||jump:input||Selects the default |
|element||div||Selects all |
|element.class||div.title||Selects all |
|element,element||div,p||Selects all |
|element1~element2||end~paragraph||Selects all |
|element1+element2||middlename+firstname||Selects all |
|:focus||name:focus||Selects the name element which has focus|