【发布时间】:2018-07-17 12:52:26
【问题描述】:
我在 Python 中对页面https://www.instagram.com/explore/tags/some_hashtag/?__a=1 做了很多请求。代码如下:
def LoadUserAgents(uafile):
"""
uafile : string
path to text file of user agents, one per line
"""
uas = []
with open(uafile, 'rb') as uaf:
for ua in uaf.readlines():
if ua:
uas.append(ua.strip())
random.shuffle(uas)
return uas
address = f'https://www.instagram.com/explore/tags/{hashtag[1:]}/?__a=1'
uas = LoadUserAgents("user-agents.txt")
ua = random.choice(uas)
headers = {
"Connection" : "close",
"User-Agent" : ua}
r = requests.get(address, proxies=proxy, timeout=30, headers=headers)
文本文件'user-agents.txt'来自here
变量proxy的一个例子是proxy={'http': 'http://104.196.45.252:80'}
我仍然可以在日志中看到我定期被禁止一段时间。
{'message': 'Please wait a few minutes before you try again.', 'status': 'fail'}
在这样的禁令之后,我立即更改了代理和用户代理,但以下请求也显示我被禁止了。
[Crawler @ 17_07_2018_15h29m34s]
Error message:{'message': 'Please wait a few minutes before you try again.', 'status': 'fail'}
Proxy:{'http': 'http://104.196.45.252:80'}
Header: {'Connection': 'close', 'User-Agent': b'Mozilla/5.0 (Windows; U; Windows NT 5.0; fr; rv:1.8.1.9pre) Gecko/20071102 Firefox/2.0.0.9 Navigator/9.0.0.3'}
[Crawler @ 17_07_2018_15h29m44s]
Error message: {'message': 'Please wait a few minutes before you try again.', 'status': 'fail'}
Proxy:{'http': 'http://52.77.242.220:80'}
Header: {'Connection': 'close', 'User-Agent': b'Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.7.3) Gecko/20040910'}
....
任何想法我做错了什么或我应该在那里添加什么以避免问题?
谢谢!
【问题讨论】:
-
有比某些 ip 或用户代理更复杂的方法来检测您是否是同一个人...例如画布指纹识别或其他指纹识别方法不可用时...您能做什么?来自python......什么都没有。
标签: python-3.x request instagram