【问题标题】:crawl only tweets metadata without the tweet text using an ID list使用 ID 列表仅抓取不包含推文文本的推文元数据
【发布时间】:2019-01-23 22:03:12
【问题描述】:

上下文:我有一个推文 ID 列表及其文本内容,我需要抓取它们的元数据。但是,我的代码也会抓取推文元数据和文本。由于我有大约 10 万条推文 ID,我不想浪费时间再次抓取推文文本。

问题:如何调整以下代码,以便仅下载推文元数据。我正在使用 tweepy 和 python 3.6。

def get_tweets_single(twapi, idfilepath):
    #tweet_id = '522778758168580098'
    tw_list = []
    with open(idfilepath,'r') as f1:#A File that Contains tweet IDS
        lines = f1.readlines()
        for line in lines:
            try:
                print(line.rstrip('\n'))
                tweet = twapi.get_status(line.rstrip('\n'))#tweepy function to crawl tweet metadata
                tw_list.append(tweet)
                #tweet = twapi.statuses_lookup(id_=tweet_id,include_entities=True, trim_user=True)
                with open(idjsonFile,'a',encoding='utf-8')as f2:
                    json.dump(tweet._json,f2)
            except tweepy.TweepError as te:
                print('Failed to get tweet ID %s: %s', tweet_id, te.message)

def main(args):
    print('hello')
# connect to twitter
    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
    api = tweepy.API(auth)
    get_tweets_single(api, idfilepath)

【问题讨论】:

    标签: python-3.x twitter metadata tweepy


    【解决方案1】:

    您不能下载有关推文的元数据。

    查看the documentation,您可以选择使用trim_user=true 排除有关用户的信息 - 但这是您唯一可以删除的内容。

    【讨论】:

      猜你喜欢
      • 2018-07-14
      • 1970-01-01
      • 2019-08-17
      • 1970-01-01
      • 2021-08-02
      • 1970-01-01
      • 2013-09-10
      • 2020-09-07
      • 1970-01-01
      相关资源
      最近更新 更多