简体   繁体   English

Twitter关于Python的爬虫

[英]Twitter Crawler on Python

I'm trying to gather tweets data from twitter using python. 我正在尝试使用python从Twitter收集推文数据。 This is my code. 这是我的代码。

#API
consumer_key = "API key"
consumer_secret = "Secret key"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)

#Access Token
access_token = "Access Token"
access_token_secret = "Access Token Secret"
auth.set_access_token(access_token, access_token_secret)

#Twitter API
api= tweepy.API(auth)
location = "%s,%s,%s" % ("35.95","128.25","1000km")
keyword = ""
wfile = open(os.getcwd()+"/twitter.txt",mode='w')
cursor = tweepy.Cursor(api.search,
                   q=keyword,
                   since='2015-01-01',
                   count=100,
                   geocode=location,
                   include_entities=True)

for i,tweet in enumerate(cursor.items()):
print("{}:{}".format(i,tweet.text))
wfile.wrtie(tweet.text+'\n')
wfile.close()

Question 1. 问题1

In this case, the tweets are from '2015-01-01', but is it possible to assign date like '2015-01-01 ~ 2015-12-31' ? 在这种情况下,推文来自“ 2015-01-01”,但是否可以分配“ 2015-01-01〜2015-12-31”之类的日期?

Question 2. 问题2。

Counts are 100 which means it will gather 100 tweets from 2015-01-01. 计数为100,这意味着它将在2015年1月1日收集100条推文。 but is there any specific gathering method I can give? 但是我可以提供任何特定的收集方法吗? Such as 100 random tweets regardless of chronological orders or 100 tweets from 2015-01-01 that have been re-tweeted most 例如100条随机推文(不考虑时间顺序),或者100条2015年1月1日发布的推文,其中大部分已被转推

Question 3. 问题3。

In this code, tweets and tags are only things I can know. 在这段代码中,tweet和标签只是我所知道的。 Is there way to find out location information of tweets? 有没有办法找出推文的位置信息? Latitude and longitude of where it has been uploaded? 它已上传到哪里的纬度和经度?

Question 4. How can I get only the hashtags? 问题4.如何仅获取主题标签? not the whole tweets 不是整个推文

Thank you very much 非常感谢你

You can use the since and until operator. 您可以使用since直到运算符。

https://api.twitter.com/1.1/statuses/user_timeline.json?include_entities=true&inc‌​lude_rts=true&screen_name=your_screen_name&since:2011-05-16&until:2011-08-16

But it will do you little good because tweets are searchable in a small time window. 但这不会给您带来什么好处,因为可以在很小的时间范围内搜索推文。 To get around this check out several resources 要解决此问题,请查看一些资源

copied from 复制自

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

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