【发布时间】:2021-06-22 04:35:04
【问题描述】:
这是我要获取的文本的屏幕截图:
检查元素的完整链接:-
https://www.youtube.com/watch?v=KwyVTQaBndU
我想从标签中获取 2021 年 6 月 21 日,请附上截图。
这是我试过的代码:
try:
postdate = driver.find_element_by_xpath("//*[@id='container']//div[@id='info']//div[@id='date']").get_attribute(
'innerText')
print(postdate)
except Exception as e:
print(e)
输出:
Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='container']//div[@id='info']//div[@id='date']"}
(Session info: chrome=91.0.4472.106)
它一直有效,但我猜 youtube 在格式上做了一些改变。所以它不起作用。
【问题讨论】:
-
你试过完整的 X 路径吗?
标签: python-3.x selenium date selenium-webdriver web-scraping