Get HTML Source of WebElement in Selenium WebDriver using Python

后端 未结 14 1952
误落风尘
误落风尘 2020-11-22 13:45

I\'m using the Python bindings to run Selenium WebDriver:

from selenium import webdriver
wd = webdriver.Firefox()

I know I can grab a webel

14条回答
  •  醉话见心
    2020-11-22 14:20

    The method to get the rendered HTML I prefer is following:

    driver.get("http://www.google.com")
    body_html = driver.find_element_by_xpath("/html/body")
    print body_html.text
    

    However the above method removes all the tags( yes the nested tags as well ) and returns only text content. If you interested in getting the HTML markup as well, then use the method below.

    print body_html.getAttribute("innerHTML")
    

提交回复
热议问题