Twitter REST API:推文提取

问题描述:

以下代码已由我编写,以提取带有特定主题标签的推文。Twitter REST API:推文提取

import json 
import oauth2 
import time 
import io 


Consumer_Key = "" 
Consumer_Secret = "" 

access_token = "" 
access_token_secret = "" 


def oauth_req(url, key, secret, http_method="GET", post_body="", http_headers=None): 
     consumer = oauth2.Consumer(key="", secret="") 
     token = oauth2.Token(key=key, secret=secret) 
     client = oauth2.Client(consumer, token) 
     content = client.request(url, method=http_method, body=post_body, headers=http_headers) 
     return content 

tweet_url = 'https://twitter.com/search.json?q=%23IPv4%20OR%20%23ISP%20OR%20%23WiFi%20OR%20%23Modem%20OR%20%23Internet%20OR%20%23IPV6' 
jsn = oauth_req(tweet_url, access_token, access_token_secret) 
print jsn 

我的主题标签是:IPv4,IPv6,ISP,互联网,调制解调器。我希望我的代码能够查看推文是否至少有一条推文应写入我的文件的井号标签。 但不幸的是,它返回的是html标签。 输出如下:

({'content-length': '338352', 'x-xss-protection': '1; mode=block', 'x-content-type-options': 'nosniff',........................ 
.............................-post-iframe" name="tweet-post-iframe"></iframe>\n <iframe aria-hidden="true" class="dm-post-iframe" name="dm-post-iframe"></iframe>\n\n</div>\n\n </body>\n</html>\n') 

在这方面的任何引线将受到赞赏。

在您的鸣叫网址是

tweet_url = 'https://twitter.com/search.json?q=%23IPv4%20OR%20%23ISP%20OR%20%23WiFi%20OR%20%23Modem%20OR%20%23Internet%20OR%20%23IPV6' 

这是网站的URL看看。 但是,如果您尝试通过Twitter API提取推文,请使用以下网址替换上述网址:

tweet_url = 'https://api.twitter.com/1.1/search/tweets.json?q=%23IPv4%20OR%20%23ISP%20OR%20%23WiFi%20OR%20%23Modem%20OR%20%23Internet%20OR%20%23IPV6'