Skip to content

First Script for Web Scraping#

When you have installed relevant packages, you're ready to go. Simply type:

Python
1
2
3
4
5
6
7
8
from browserist import Browser

browser = Browser()
browser.open.url("https://example.com")
headline = browser.get.text("//h1")
print(headline)
browser.wait.seconds(5)
browser.quit()

Or use the built-in context manager so the browser automatically closes when done or if an error occurs:

Python
1
2
3
4
5
6
7
from browserist import Browser

with Browser() as browser:
    browser.open.url("https://example.com")
    headline = browser.get.text("//h1")
    print(headline)
    browser.wait.seconds(5)