問題:
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