web使用selenium python抓取twitter时间戳

时间:2022-04-24 01:22:57
dates = browser.find_elements_by_class_name('_timestamp')

This only gives the current time and month like '4h', 'Mar 7'. How can I get year-month-date using selenium??

这只给出了当前时间和月份,如'4h','Mar 7'。如何使用硒获得年月日?

1 个解决方案

#1


0  

Code:

码:

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)

Output:

输出:

['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']

#1


0  

Code:

码:

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)

Output:

输出:

['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']