如何根据时间范围条件从网站获取数据

时间:2019-07-29 06:42:13

标签: python datetime xpath datetimerangefield

我正在xpath中从网站获取数据,我需要根据时间范围条件过滤数据 来自网站的样本数据

published_dates = ["7/11/2019 at 07:39 AM","7/11/2019 at 12:09 AM","7/11/2019 at 11:59 PM","7/11/2019 at 06:00 AM"]

from datetime import datetime
import datetime as dt
published_dates = result.xpath('.//td[4]//text()').extract()
datetime_object = datetime.strptime('published_dates', '%b %d %Y at %I:%M%p')
checkTime = dt.time(7,0,0)
filtered_dates = []
for d in published_dates:
  dt1 = datetime.strptime(d, '%d/%m/%Y at %I:%M %p')
  if ( checkTime < dt1.time()) :
      filtered_dates.append(dt1.strftime("%d/%m/%Y at %I:%M %p"))
print('filtered_dates : ', filtered_dates)

0 个答案:

没有答案