Get HTML source of WebElement in Selenium WebDriver using Python

问题:

I'm using the Python bindings to run Selenium WebDriver:我正在使用 Python 绑定来运行 Selenium WebDriver:

from selenium import webdriver
wd = webdriver.Firefox()

I know I can grab a webelement like so:我知道我可以像这样抓取一个 webelement:

elem = wd.find_element_by_css_selector('#my-id')

And I know I can get the full page source with...而且我知道我可以获得完整的页面源代码...

wd.page_source

But is there a way to get the "element source"?但是有没有办法获得“元素来源”?

elem.source   # <-- returns the HTML as a string

The Selenium WebDriver documentation for Python are basically non-existent and I don't see anything in the code that seems to enable that functionality. Python 的 Selenium WebDriver 文档基本上不存在,我在代码中看不到任何似乎启用该功能的内容。

What is the best way to access the HTML of an element (and its children)?访问元素(及其子元素)的 HTML 的最佳方式是什么?


解决方案:

参考一: https://en.stackoom.com/question/UTeS
参考二: https://stackoom.com/question/UTeS
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章