🚀 We are hiring! See open positions

How to get page source in Selenium?

When web scraping, we often want to retrieve full page source (full HTML of the web page) we can parse it for data using tools like BeautifulSoup. Using Python and Selenium, to get the page source we can use driver.page_source attribute:

python
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://httpbin.dev/html")
print(driver.page_source)

âš  It's possible that this command will retrieve page source before the page fully loads if it's a dynamic javascript page. For more see how-to-wait-for-page-to-load-in-selenium

Scale Your Web Scraping
Anti-bot bypass, browser rendering, and rotating proxies — all in one API. Start with 1,000 free credits.
No credit card required 1,000 free API credits Anti-bot bypass included
Not ready? Get our newsletter instead.