0

以下代碼已由我編寫,以提取帶有特定主題標籤的推文。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') 

在這方面的任何引線將受到讚賞。

回答

1

在您的鳴叫網址是

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'