【发布时间】:2020-06-15 09:26:09
【问题描述】:
我正在从网站上抓取图像,但 xpath 因元素而异。我读到 this post 可以通过 find_elements_by_xpath 使用 or 函数。
但是,当我尝试复制示例时,我无法再提取图像的 src。我做错了 or 功能吗?
images=driver.find_elements_by_xpath('// img[ @ id = "ember51"]' or '// img[@id="ember52"]')
print(images.get_attribute('src'))
错误:
AttributeError: 'list' object has no attribute 'get_attribute'
我试图做一个 for 循环,所以 src 可以被刮掉:
images=driver.find_elements_by_xpath('// img[ @ id = "ember51"]' or '// img[@id="ember52"]')
for image in images:
print(images.get_attribute('src'))
但是当我使用 for 循环时,我得到了同样的错误。不知道如何使这项工作。
【问题讨论】: