Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.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
Twitter不再适用于python请求库_Python_Twitter_Python Requests_Twitterapi Python - Fatal编程技术网

Twitter不再适用于python请求库

Twitter不再适用于python请求库,python,twitter,python-requests,twitterapi-python,Python,Twitter,Python Requests,Twitterapi Python,我有一个python函数,它使用requests库和BeautifulSoup来抓取特定用户的tweet import requests from bs4 import BeautifulSoup contents = requests.get("https://twitter.com/user") soup = BeautifulSoup(contents.text, "html.parser") 当请求库访问Twitter时,它使用传统版本的Twitter。但是,由于Twitter最近放

我有一个python函数,它使用requests库和BeautifulSoup来抓取特定用户的tweet

import requests
from bs4 import BeautifulSoup

contents = requests.get("https://twitter.com/user")
soup = BeautifulSoup(contents.text, "html.parser")
当请求库访问Twitter时,它使用传统版本的Twitter。但是,由于Twitter最近放弃了对其旧版本的支持,请求库不再工作,并返回html代码,表示此版本的Twitter已过时


有没有办法让请求库访问更新版本的Twitter?

请求库将访问您传递给它的URL。我建议检查并更新您的代码,以符合最新版本。

无法直接回答(并且没有足够的要点可供评论),但有相同的问题,我确实找到了一些新工具。使用请求_html获取tweets(请参阅他们的tweets.py模块)。是另一个强大的python工具,用于抓取推文。

我也遇到了这个问题。造成这种情况的根本原因是Twitter拒绝使用“遗留”浏览器,不幸的是,它包括Python的请求库

Twitter通过查看作为请求一部分发送的
用户代理
头来确定您使用的浏览器。所以我解决这个问题的方法就是欺骗这个标题

在你的特殊情况下,试着做以下事情:

import requests
from bs4 import BeautifulSoup

contents = requests.get(
    "https://twitter.com/user",
    headers={"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36"}
)
soup = BeautifulSoup(contents.text, "html.parser")