我试图得到所有的链接和链接的背景图像内的一个特定的div,但我似乎不能得到他们。
我试图在paint_wrap div而不是paint_color中获取链接和背景图像。
于飞:
<div id="timer" style="display:inline-block">
<div class="paint_wrap">
<div class="paint_color">
<img src="http://link.com/img/6EAwxqqt6J7aKcn6B6pO.gif" class="pick" width="30" height="30" border="0" alt="">
<img src="http://link.com/img/arrow.gif" class="arrow" width="27" height="15" border="0" alt="">
</div>
<a href="tx.php?id=91760&a=f899139df5e105939643&s=dba9df3b0d18635362fd70d1ec51f201" target="_top" class="evJ3Ic2F5rYtXH4sPFKN" alt=""></a>
<a href="tx.php?id=91760&a=3644a684f98ea8fe223c&s=dba9df3b0d18635362fd70d1ec51f201" target="_top" class="Rrp84pHupovp4G9R8DfJ" alt=""></a>
<a href="tx.php?id=91760&a=94f6d7e04a4d45203530&s=dba9df3b0d18635362fd70d1ec51f201" target="_top" class="z071fnIXwHK7MDd7M58t" alt=""></a>
<a href="tx.php?id=91760&a=18d8042386b79e2c279f&s=dba9df3b0d18635362fd70d1ec51f201" target="_top" class="UT94OVZ614YGvkFIuh4P" alt=""></a>
<a href="tx.php?id=91760&a=cee631121c2ec9232f3a&s=dba9df3b0d18635362fd70d1ec51f201" target="_top" class="ZC7TO9wC576wN0Q9017j" alt=""></a>
<a href="tx.php?id=91760&a=d490d7b4576290fa60eb&s=dba9df3b0d18635362fd70d1ec51f201" target="_top" class="G2e7xW9ii7Lp40kH140X" alt=""></a>
<a href="http://www.other-link.com/?5974792" target="_blank" class="open"><img src="http://link.com/tx/o.gif" width="15" height="15" border="0" alt=""></a>
</div>
</div>
我尝试过的:
WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//*[@id='timer']/div/a"))) # Wait is fine
elements = self.driver.find_element(By.XPATH, "//*[@id='timer']/div/a")
for element in elements:
print(element.get_attribute("href"))
print(element.value_of_css_property("background-image"))
我也尝试过使用css选择器。
我得到的错误:“WebElement”对象不可迭代
我希望有人能给我指个方向。
1条答案
按热度按时间jogvjijk1#
您必须在下面的行中使用'find_elements',而不是'find_element':