【发布时间】:2017-02-14 00:16:16
【问题描述】:
我是 Python 和 Twython 的新手,可以使用#3 的一些帮助。我正在做一些研究,并希望通过用户提取推文并包含某个关键字。我也想将它导出到 csv 但弄清楚它是第一部分。谢谢:)
# Bring in the module Twython which pulls from Twitter's API
from twython import Twython, TwythonError
# Making variables for my twitter API keys
CONSUMER_KEY = 'my personal input hered'
CONSUMER_SECRET = 'my personal input here'
ACCESS_KEY = 'my personal input here'
ACCESS_SECRET = 'my personal input here'
twitter = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)
## 1) This block works and searches for tweets containing a specific keyword
print(twitter.search(q='python'))
## 2) This block works as well and returns all tweets by username
try:
user_timeline = twitter.get_user_timeline(screen_name='')
except TwythonError as e:
print e
for tweets in user_timeline:
print tweets['text']
## 3) I can't get this one to work. It is supposed to return all tweets by
# username AND containing keyword
*try:
user_timeline = twitter.get_user_timeline(screen_name='ThePSF') and twitter.search(q='lines')
except TwythonError as e:
print e
for tweets in user_timeline and q:
print tweets['text']*
【问题讨论】:
标签: python api twitter twython