1 回答

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
添加回答
舉報