Skip to main content
This example demonstrates the fundamentals of web scraping with nodriver, including finding elements, extracting data, and handling interactive content.

Complete example

Here’s a real-world scraping example that searches Google and monitors network requests:

Step-by-step breakdown

1

Start the browser

Initialize nodriver and create a browser instance:
2

Add network handlers

Monitor network activity by adding event handlers:
These handlers will be called automatically for every network request and response.
3

Find elements by text

Use find() with best_match=True to locate elements by their text content:
The best_match flag picks the element with the most similar text length, filtering out irrelevant matches.
4

Use CSS selectors

Find elements using standard CSS selectors:
5

Extract data

Get all URLs from the current page:

Key methods

Finding elements

Interacting with elements

The await tab statement updates all references and allows the script to “breathe”, which is useful when the script runs faster than the browser can render.

Network monitoring

You can monitor all network requests and responses:
Always use await tab.find() or await tab.select() instead of hardcoded sleeps. These methods automatically retry for up to 10 seconds, making your scripts more robust.