dates = browser.find_elements_by_class_name('_timestamp')
这只给出当前时间和月份,如"4h"、"Mar 7"。如何使用硒获取年月日期?
代码:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://twitter.com/search?f=news&vertical=news&q=crypto&src=typd')
dates = [element.get_attribute('title') for element in driver.find_elements_by_xpath('//a[starts-with(@class, "tweet-timestamp js-permalink js-nav js-tooltip")]')]
print(dates)
输出:
['7:41 AM - 14 Mar 2018', '3:42 PM - 12 Mar 2018', '5:58 AM - 13 Mar 2018', '5:14 AM - 14 Mar 2018', '1:44 AM - 9 Mar 2018', '9:12 PM - 12 Mar 2018', '5:11 AM - 14 Mar 2018', '9:50 AM - 7 Mar 2018', '11:01 PM - 13 Mar 2018', '4:09 AM - 14 Mar 2018', '10:22 AM - 6 Mar 2018', '8:40 AM - 7 Mar 2018', '8:48 AM - 9 Mar 2018', '7:48 AM - 14 Mar 2018', '5:11 AM - 14 Mar 2018', '10:32 AM - 14 Mar 2018', '9:25 AM - 7 Mar 2018', '10:05 PM - 12 Mar 2018', '5:49 AM - 12 Mar 2018', '12:10 PM - 14 Mar 2018']