我正在使用以下 python 代碼來啟動 Firefox 網(wǎng)頁。from selenium import webdriverfrom selenium.webdriver.common.keys import Keysdriver= webdriver.Firefox()driver.get("https://www.quora.com")啟動后,如果我知道這個(gè)標(biāo)簽的 xpath。<input class="text header_login_text_box ignore_interaction" type="text" name="email" tabindex="1"data-group="js-editable"placeholder="Email"w2cid="wZgD2YHa18" id="__w2_wZgD2YHa18_email">如果我現(xiàn)在是屬性的名稱,我可以使用以下命令在 python 上使用 selenium webdriver 提取屬性。dict['attribute'] = driver.find_element_by_xpath(x_path).get_attribute(attribute)所以我的輸出將是dict = { 'attribute':value}請幫助我找出提取所有屬性及其值的方法,即使我不知道它具有的所有屬性是什么。我的預(yù)期輸出是dict = { "class" : "text header_login_text_box ignore_interaction" "type" : "text" "name":"email" "tabindex" : "1" "data-group" : "js-editable" "placeholder" : "Email" "w2cid" : "wZgD2YHa18" "id" : "__w2_wZgD2YHa18_email" }我不確定這有多大可能,但我希望像在字典中一樣,即使不知道密鑰,我們也可以提取數(shù)據(jù)。謝謝
3 回答

Smart貓小萌
TA貢獻(xiàn)1911條經(jīng)驗(yàn) 獲得超7個(gè)贊
獲取placeholder
屬性使用get_attribute()
element.get_attribute('placeholder')

qq_遁去的一_1
TA貢獻(xiàn)1725條經(jīng)驗(yàn) 獲得超8個(gè)贊
定義要提取占位符的輸入標(biāo)簽的 xpath。
xpath_input = "//input[@id='__w2_wZgD2YHa18_email']"
driver.find_element_by_xpath(xpath_input)
獲取元素后,您可以通過以下方式提取placeholder(“電子郵件”)get_attribute("placeholder")
添加回答
舉報(bào)
0/150
提交
取消