我为Instagram帖子编写了一个解析器,在本地机器上一切正常
代码:
import requests
session = requests.Session()
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36'
}
session.headers.update(headers)
url = 'https://www.instagram.com/p/BwxCPidhe0V/'
response = session.get(url)
if response.history:
print("Request was redirected")
for resp in response.history:
print(resp.status_code, resp.url)
print("Final destination:")
print(response.status_code, response.url)
else:
print("Request was not redirected")
执行此代码时,我的请求不会重定向到授权页https://www.instagram.com/accounts/login/?next=/p/BwxCPidhe0V/
但是当我上传任何主机的代码(Heroku、repl.it、pythonanywhere)时,我的请求被重定向到授权页面
如何实现此系统的旁路,以便在通过托管请求时不会重定向到授权页面
最好使用python标准请求库,而不是使用solonium
沙箱: https://repl.it/@briler/bypass-Instagram-parsing-protection#main.py
目前没有回答
相关问题 更多 >
编程相关推荐