我正在尝试为我的项目建立一个网站,但我在通过Selenium从这个website中删除图像名称时遇到了问题

使用以下代码,我可以使用selenium从网站返回text数据
results = driver.find_elements_by_css_selector("li.result_content")
for result in results:
company_name = result.find_element_by_tag_name("h3").get_attribute("innerText")
product_name = result.find_element_by_id('sProdName').get_attribute("innerText")
product_paymode = result.find_element_by_id('paymode').get_attribute("innerText")我被告知要使用get_attribute("innerText"),因为有几个项目是隐藏的,而get_attribute("innerText")会帮助我获取隐藏的项目。(的确如此,它是有效的)
我的问题是:如何抓取prod-feature-icon类,以告诉我该图片是否为active?
发布于 2016-09-14 19:49:07
为什么不使用find_element_by_class_name?
feature_icon = result.find_element_by_class_name("prod-feature-icon")然而,值得注意的是,具有这个类名的对象实际上是一个UL,其中有几个图像,因此您需要决定要从中处理哪个图像。或者,您可以使用以下命令遍历它们
for item in feature_icon.find_elements_by_tag_name('img'):
print(item.get_attribute('src'))当然,这仍然不会告诉您项目是活动的还是不活动的,因为这似乎不是由CSS决定的,而是由图像的阴影决定的
https://stackoverflow.com/questions/39489612
复制相似问题