python中判断xpath是否存在

编程入门 行业动态 更新时间:2024-10-10 11:26:43

python中判断xpath<a href=https://www.elefans.com/category/jswz/34/1759542.html style=是否存在"/>

python中判断xpath是否存在

我目前正在使用selenium、bs4和python进行抓取,但是在检查Xpath是否存在时遇到了一个问题,下面是我的代码:def hasXpath(xpath):

try:

browser.get(quote_page)

self.browser.find_element_by_xpath(xpath)

return True

except:

return False

# IF PRICELIST EXISTS CONDITION/

if hasXpath("(//div[@id='product-header h4']//span)[last()-2]") or hasXpath("(//div[@id='product-header']//span)[last()-1]") or hasXpath("(//div[@id='product-header']//span)[last()]"):

#No. of Items Per Retail(NEED LOGIN)

somthing = browser.find_element_by_xpath("(//div[@id='product-header']//td)[21]").get_attribute("innerText")

print(somthing)

#Retail Price(NEED LOGIN)

browser.get(quote_page)

somthing1 = browser.find_element_by_xpath("(//div[@id='product-header'

更多推荐

python中判断xpath是否存在

本文发布于:2024-03-06 20:54:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1716355.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:是否存在   python   xpath

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!