Selenium in python accessing HTML source

  • 1 Replies
  • 949 Views
Selenium in python accessing HTML source
« on: May 05, 2016, 21:51:48 pm »
Can I get the HTML source in a variable using selenium module with Python?

I'm trying to do something like this:

Code
from selenium import webdriver
browser = webdriver.Firefox()
browser.get(raw_input("url:"))
if "text" in html_source:
    # logic
else:
    # logic

Is this possible? How can I access the HTML source?

*

Oren

  • **
  • 59
Re: Selenium in python accessing HTML source
« Reply #1 on: May 30, 2016, 23:21:25 pm »
You can if you call the page_source property:

Code
from selenium import webdriver
browser = webdriver.Firefox()
browser.get(raw_input("url: "))
html_source = browser.page_source
if (condition) in html_source:
    # logic
else:
    # logic

 

Sitemap 1 2 3 4 5 6 7 8