gpt4 book ai didi

python - 我需要从 Xpath 获取图像 src

转载 作者:太空宇宙 更新时间:2023-11-03 20:42:37 27 4
gpt4 key购买 nike

enter image description here

我正在使用 Python 从网页中获取一些元素,我需要使用 Image 标签的 Xpath 代码获取 SRC 路径。

我尝试从中获取数据的 Xpath 如下:

//*[@id="product_24793"]/a/figure/img

我已经尝试过将这两种格式用于 Xpath

//*[@id="product_24793"]/a/figure/img/@src

//*[@id="product_24793"]/@src

我已经尝试过的代码如下:


imgsrc = driver.find_elements_by_xpath('//*[@id="product_24793"]/a/figure/img')

for ele in imgsrc:
print(ele.text)

path = ele.text

我想要 src 路径作为结果

谢谢。

最佳答案

使用get_attribute()获取src值。

imgsrc = driver.find_elements_by_xpath('//*[@id="product_24793"]/a/figure/img[@class="top"]')

for ele in imgsrc:
print(ele.get_attribute('src'))

关于python - 我需要从 Xpath 获取图像 src,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56775503/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com