【发布时间】:2019-11-17 00:10:07
【问题描述】:
我想在 Python 上使用 selenium 提取“首次发布”日期,但即使在通过浏览器的检查选项卡查找 xpath 时获得了成功的结果,我在尝试获得任何可见日期结果时也遇到了问题,我确实得到了元素的成功长度结果,但我的控制台上没有日期的文本结果。
我的代码:
import time
from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'C:\\Users\\MyComputer\\PycharmProjects\\SeleniumProject\\venv\\Lib\site-packages\\selenium\\webdriver\\common\\geckodriver.exe')
driver.get('https://tools.cisco.com/security/center/publicationListing.x?resourceIDs=93036,5834,80720&apply=1,1,1&totalbox=3&pt0=Cisco&cp0=93036&pt1=Cisco&cp1=5834&pt2=Cisco&cp2=80720#~FilterByProduct')
time.sleep(20)
prices = driver.find_elements_by_xpath('//span[@class="ng-binding" and contains(text(),"GMT")]')
for post in prices:
if post.text != "":
print(post.text)
print(len(prices))
driver.close()
我已经在网站上尝试了其他 visible xpaths 来测试 python,当你打开链接时,我可以看到屏幕上显示的 20 个漏洞标题,所以我假设我必须告诉 selenium 单击每个链接并提取日期并为每个标题执行此操作?但是,我怎样才能通过浏览器检查选项卡一次性获得它们呢?
感谢所有帮助, 谢谢,
【问题讨论】:
标签: python selenium selenium-webdriver