我正在尝试获取产品图像的所有链接&{a1}
但作为回报,我得到的只是图像的一个url链接。在
当我试图查找列表的长度时,甚至没有得到6个webelements(product\u image\u url2)
product_image_url2 = self.browser.find_elements_by_xpath('//*[@id="main-image-
container"]/ul/li/span/span/div/img')
product_image_url2_count = len(product_image_url2)
print product_image_url2_count
image_url2 = []
for curr_product_image_url2 in product_image_url2:
image_url2.append(curr_product_image_url2.get_attribute("src"))
product_dict['image url2']=image_url2
一个css替代方案来匹配这些
#
是一个id选择器。img
是一个类型选择器(用于标记)。两者之间的space
是descendant combinator
,这意味着{altImages
元素的子元素。:not([alt])
指定子img
没有alt
属性。[]
是属性选择器,:not
是CSSpseudo-class
。阅读关于他们的here。在代码:
^{pr2}$下面是获取左侧img元素的正确xpath。在
以下代码和输出:
^{pr2}$输出: 6 https://images-na.ssl-images-amazon.com/images/I/31JLKXyjA5L.SS40.jpghttps://images-na.ssl-images-amazon.com/images/I/51ZZMf1JVfL.SS40.jpghttps://images-na.ssl-images-amazon.com/images/I/416%2BBQU%2BtuL.SS40.jpghttps://images-na.ssl-images-amazon.com/images/I/41CdeeG0HGL.SS40.jpghttps://images-na.ssl-images-amazon.com/images/I/41bZb0qgNPL.SS40.jpghttps://images-na.ssl-images-amazon.com/images/I/219h80ACoQL.SS40.jpg
您的xpath错误。尝试使用xpath。在
如果你想在字典中存储,请尝试下面的代码。在
^{pr2}$输出:
相关问题 更多 >
编程相关推荐