get html selenium python code example
Example 1: python selenium get html content
element.get_attribute('innerHTML')
Example 2: python selenium web scraping example
#Python example - use chrome driver to open google url and enter into search bar "Why is python so awesome"
#required imports
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
#open driver
PATH_TO_DRIVER = './chromedriver'
driver = webdriver.Chrome(executable_path=PATH_TO_DRIVER)
#launch url using driver
driver.get('https://google.com')
#find element to manipulate e.g. by element name. 'q' is the element name of the google search bar
element = driver.find_element_by_name('q')
#write text into search bar
element.send_keys('Why is python so awesome')
#simulates 'Enter' key
element.send_keys(Keys.ENTER)
Example 3: how to get html code in selenium python
#_*_coding: utf-8_*_
from selenium import webdriver
import time
# start web
browserbrowser=webdriver.Firefox()
# get source
codebrowser.get("https://en.wikipedia.org")
html = browser.page_source
time.sleep(2)
print(html)
# close web browser
browser.close()
Example 4: get script text selenium python
info.get_attribute('innerHTML')