【发布时间】:2020-04-01 20:03:51
【问题描述】:
我有一个挂在 url 上的爬虫 python 脚本:pulsepoint.com/sellers.json
机器人使用标准请求来获取内容,但返回错误 404。在浏览器中它可以工作(有 301 重定向,但请求可以跟随)。我的第一个预感是这可能是请求标头问题,所以我复制了我的浏览器配置。代码是这样的
crawled_url="pulsepoint.com"
seller_json_url = 'http://{thehost}/sellers.json'.format(thehost=crawled_url)
print(seller_json_url)
myheaders = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language': 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding': 'gzip, deflate, br',
'Connection': 'keep-alive',
'Pragma': 'no-cache',
'Cache-Control': 'no-cache'
}
r = requests.get(seller_json_url, headers=myheaders)
logging.info(" %d" % r.status_code)
但我仍然收到 404 错误。
我的下一个猜测:
- 登录?此处未使用
- 饼干?不是我能看到的
那么他们的服务器如何阻止我的机器人?这是一个应该顺便爬的url,没有什么违法的..
提前致谢!
【问题讨论】:
标签: python request web-crawler robot