python - Python Selenium 在特定日期查找元素(标题)
问题描述
我正在使用 Selenium 取回在特定日期发布的一些文章
我试过了:
driver.get('https://www.globalcapital.com/Asia/Bonds/Corp')
while True:
links=[link.get_attribute('href') for link in driver.find_elements_by_xpath("//div[contains(@title,'01 Feb 2021')/preceding::a[2]")]
for link in links:
# I want to return all href first to a csv
# and then return to the title of the article
但是“不是有效的 XPath 表达式”,我在这里有两个问题:
- 进行仅用于兄弟元素吗?2.我怎样才能得到日期并返回元素来精确href并获取文本?
提前致谢!
解决方案
它无效,因为您忘记了右方括号。尝试
"//div[contains(@title,'01 Feb 2021')]/preceding::a[2]"
不,preceding
/following
轴不仅用于兄弟姐妹。preceding-sibling
/following-sibling
仅用于兄弟姐妹
推荐阅读
- docker - 节点重启时延迟 Docker Swarm 副本重新调度
- python - 如何在一个图表中绘制多个文件?
- reactjs - React & Next.js — Bug: getting previous page's value from session storage
- apk - “app not installed” Apk 编辑器编辑清单 Android 存储位置
- javascript - 如何将回调函数返回的值赋给变量?从另一个问题无法理解。关于异步调用
- github - 如何从 GitHub 包中删除旧的快照工件
- javascript - 在 jsfiddle 中,它在纯 javascript 中工作,但是 - 当我在我的代码中包含它时,如果不包含 jquery,它就无法工作
- visual-studio-app-center - 从 AppCenter 下载屏幕截图(或其他构建工件)
- flutter - 擦除颤动网络中图像的动画
- python - 尽管运行了“conda install”,但 Python 包并未升级