Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对于列表中的每个趋势,使用PythonTwitter拉取1000条最近的推文(并删除/排除转发)_Python_Twitter_Tweets_Python Twitter - Fatal编程技术网

对于列表中的每个趋势,使用PythonTwitter拉取1000条最近的推文(并删除/排除转发)

对于列表中的每个趋势,使用PythonTwitter拉取1000条最近的推文(并删除/排除转发),python,twitter,tweets,python-twitter,Python,Twitter,Tweets,Python Twitter,使用pythontwitter库()我试图使用yahoo Where-on-earth ID检索某个位置的前10大趋势的1000条最新tweet,但似乎不知道如何从列表中的趋势中检索tweet 我不知道我是否在文档中遗漏了什么,也无法在网上找到任何关于如何从返回的列表中获取特定于趋势的推文以及如何删除转发的示例 import twitter from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer ACCESS_

使用pythontwitter库()我试图使用yahoo Where-on-earth ID检索某个位置的前10大趋势的1000条最新tweet,但似乎不知道如何从列表中的趋势中检索tweet

我不知道我是否在文档中遗漏了什么,也无法在网上找到任何关于如何从返回的列表中获取特定于趋势的推文以及如何删除转发的示例

import twitter
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer


ACCESS_TOKEN = 'XXXX'
ACCESS_TOKEN_SECRET = 'XXXX'
CONSUMER_KEY = 'XXXX'
CONSUMER_SECRET = 'XXXX'

# Define the location id for the UK
WOEID = 23424975
# Define language of tweets
LANG = "en"
# Define type of tweets we are after
TWEETS_TYPE = "recent"
# Define max number of tweets per trend
MAX_STATUSES = 1000

# API config
# API with request rate limited
api = twitter.Api(CONSUMER_KEY,
                  CONSUMER_SECRET,
                  ACCESS_TOKEN,
                  ACCESS_TOKEN_SECRET,
                  sleep_on_rate_limit=True)

print(api.VerifyCredentials())

# Query the Twitter API for the current top 10 trends in the UK.
uk_trends = api.GetTrendsWoeid(WOEID)
print(uk_trends)


# Return the 1000 most recent tweets for each trend
# This is where I want to retrieve the tweets per trend
for trend in uk_trends:
    count = MAX_STATUSES
    trend = trend
    search_results = api.GetSearch(term=trend, count=count)
    print(search_results)

我应该改用twitter API本身吗?

我可以通过访问Trend()对象的name属性,将其解析为字符串并遍历代码中返回的结果来解决这个问题,如下所示:

```


```

要删除转发,您可以使用q参数和“-filter:retweets”将其排除在搜索之外
import os
import json
import csv

import twitter
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
import pandas as pd
import matplotlib.pyplot as plt

ACCESS_TOKEN = 'XXXX'
ACCESS_TOKEN_SECRET = 'XXXX'
CONSUMER_KEY = 'XXXX'
CONSUMER_SECRET = 'XXXX'

# Define the location id for the UK
# With Yahoo Where on Earth ID
WOEID = 23424975
# Define language of tweets
LANG = "en"
# Define type of tweets we are after
TWEETS_TYPE = "recent"
# Define max number of tweets per trend
MAX_STATUSES = 10

# API configuration
# API with request rate limited
api = twitter.Api(CONSUMER_KEY,
                  CONSUMER_SECRET,
                  ACCESS_TOKEN,
                  ACCESS_TOKEN_SECRET,
                  sleep_on_rate_limit=True)

# Check twitter account api details are correct
# print(api.VerifyCredentials())

# Query the Twitter API for the current top 10 trends in the UK.
uk_trends = api.GetTrendsWoeid(WOEID)

print(uk_trends)


# Return the 1000 most recent tweets for each trend
for trend in uk_trends:
    '''
    Extract name of each trend returned by Trend model
    and search required count value of recent tweets per trend
    '''
    trend = str(trend.name)
    count = MAX_STATUSES
    search_results = api.GetSearch(term=trend, count=count)
    print(search_results)