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
添加回答
举报