python - Python Selenium 获取属性“href”错误
问题描述
我正在尝试从链接中获取 href,请找到我的代码:
url ='http://money.finance.sina.com.cn/bond/notice/sz149412.html'
link = driver.find_element_by_xpath("//div[@class='blk01'])//ul//li[3]//a[contains(text(),'发行信息']").get_attribute('href')
print(link)
错误
invalid selector: Unable to locate an element with the xpath expression
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//div[@class='blk01'])//ul/li[3]//a[contains(text(),'发行信息']' is not a valid XPath expression.
似乎它不是有效的 xpath,但我无法找出错误,任何帮助将不胜感激!
谢谢
解决方案
试试这个:
link = driver.find_element_by_xpath('//div[@class="blk01"]//ul//li[3]//a[contains(text(), "发行信息")]')
print(link.get_attribute("href"))
推荐阅读
- ruby - Ruby API response - how to action
- javascript - jQuery find 停止工作并且元素看起来很奇怪
- javascript - 需要 Javascript 内联 SVG 帮助
- php - Conditionally alter specific product price in Woocommerce
- audiokit - IOS 的 Audiokit MIDI 设备
- spring - compound key and CrudRepository in Spring boot
- python - Separate blocks of text python
- spring - Spring Boot 表单请求跟踪
- r - data.table::fread 文本中的新行问题
- java - 错误 pom.xml 配置与 Spring Boot + Spring MVC + Primefaces + JoinFaces