Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我需要从Xpath获取一个图像src_Python_Xpath - Fatal编程技术网

Python 我需要从Xpath获取一个图像src

Python 我需要从Xpath获取一个图像src,python,xpath,Python,Xpath,我正在使用Python从网页中获取一些元素, 我需要使用图像标记的Xpath代码从图像标记获取SRC路径 我试图从中获取数据的Xpath如下所示: //*[@id="product_24793"]/a/figure/img 我已经尝试将这两种格式用于Xpath //*[@id="product_24793"]/a/figure/img/@src //*[@id="product_24793"]/@src 另外,我已经尝试过的代码如下: imgsrc = driver.find_eleme

我正在使用Python从网页中获取一些元素, 我需要使用图像标记的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\u 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'))
使用
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'))