Python Selenium accessing HTML source

0
0

How can I get the HTML source in a variable using the Selenium module with Python?

I wanted to do something like this:

from selenium import webdriver
browser
= webdriver.Firefox()
browser
.get(raw_input("Enter URL: "))
if "whatever" in html_source:
# Do something
else:
# Do something else

How can I do this? I don’t know how to access the HTML source.

  • You must to post comments
0
0

You need to call the page_source property. See below.

from selenium import webdriver
browser
= webdriver.Firefox()
browser
.get(raw_input("Enter URL: "))
html_source
= browser.page_source
if "whatever" in html_source:
# do something
else:
# do something else
  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website