简体   繁体   English

Python 2.7 Twitter抓取工具

[英]Python 2.7 Twitter Scraper

When I change the end time of my cursor to the 29th it returns 0 for everything. 当我将光标的结束时间更改为29时,所有内容都返回0。 But when I change it to the 28th I get all the information. 但是当我将其更改为28号时,我会获得所有信息。

start = "2017-02-25"
    end = "2017-02-29"
    for status in tweepy.Cursor(api.search, q=i,since=start,until=end,lang="en").items():

        parsed = status._json
        usercount[parsed['user']['name'].encode("utf-8")]+=1
        userfollowers[parsed['user']['name'].encode("utf-8")]= parsed['user']['followers_count']
        mostretweets[parsed['text'].encode('utf-8')] = parsed['retweet_count']         
        mostfav[parsed['text'].encode('utf-8')] = parsed['favorite_count'] 

2月29日不存在(至少在2017年),这不是有效的日期...

Seek to use datetime , so there will already be a validation of the date. 尝试使用datetime ,因此将已经有一个日期验证。

from datetime import datetime
datetime(2017, 2, 29)

ValueError: day is out of range for month

start = datetime(2017, 2, 25).strftime("%Y-%m-%d")
end = datetime(2017, 2, 28).strftime("%Y-%m-%d")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM