亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 xpath 查找類內部的值?(硒 Chrome 驅動程序)

如何使用 xpath 查找類內部的值?(硒 Chrome 驅動程序)

慕萊塢森 2023-08-08 17:12:30
我正在嘗試使用 ChromeDriver 從以下 html 代碼中提取值“/mva/library/20120730/93135a040s.gif”:目前,我的代碼:is_black_white = driver.find_elements_by_xpath("http://div[@class='aj cw cy db ImgCaptionCntnrHover']/img[@data-filterwithidind='True']")x = is_black_white[0].get_attribute("title src")print(x)返回“無”。我感覺我已經很接近了。任何幫助將非常感激!謝謝!
查看完整描述

1 回答

?
慕田峪7331174

TA貢獻1828條經驗 獲得超13個贊

xpath 不正確。您可以嘗試這個解決方案。請注意,有一個雙斜杠表示任何帶有 img 標簽的子節點。


WebDriverWait(driver, 30).until(EC.presence_of_all_elements_located((By.XPATH, "//div[@class='aj cw cy db ImgCaptionCntnrHover']//img")))

 

is_black_white = driver.find_elements_by_xpath("//div[@class='aj cw cy db ImgCaptionCntnrHover']//img")


print(len(is_black_white))

x = is_black_white[0].get_attribute("src")

print(x)


#Prints all the src urls

for ele in is_black_white:

    print(ele.get_attribute("src"))

輸出:


4

https://www.mcmaster.com/mva/library/20120730/93135a040s.gif

https://www.mcmaster.com/mva/library/20120730/93135a040s.gif

https://www.mcmaster.com/mva/library/20120730/94735a040s.gif

https://www.mcmaster.com/mva/library/20120730/93135a040s.gif

https://www.mcmaster.com/mva/library/20120730/94735a040s.gif


查看完整回答
反對 回復 2023-08-08
  • 1 回答
  • 0 關注
  • 109 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號