nandesuka
nandesuka

Reputation: 799

Print dom after Selenium driver.get

I'm used to requests where I can just print the response after I do make a GET request. I find myself unsure if parts of the page are in the resonse or not, particularly when the website uses React or jQuery.

Is there a way I can do the same with Selemium?

Like this?

    DRIVER_PATH = '/usr/bin/chromedriver'
    options = webdriver.ChromeOptions()
    options.add_argument("--headless")
    driver = webdriver.Chrome(executable_path=DRIVER_PATH, options=options)
    driver.get('example.com')

    # Print the DOM

    driver.quit()

Upvotes: 0

Views: 1010

Answers (1)

Jortega
Jortega

Reputation: 3790

You are looking for driver.page_source.

from selenium import webdriver

DRIVER_PATH = '/usr/bin/chromedriver'
options = webdriver.ChromeOptions()
options.add_argument("--headless")
driver = webdriver.Chrome(executable_path=DRIVER_PATH, options=options)
driver.get('https://google.com')

# Print the DOM
print(driver.page_source)

driver.quit()

Upvotes: 2

Related Questions