找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 2286|回复: 1

[求助] python爬虫 请求 无限循环重定向

1

主题

1

帖子

1

积分

贫民

积分
1
363685202 发表于 2018-5-12 22:18:08 | 显示全部楼层 |阅读模式
需要请求的url:http://list.tmall.hk/search_prod ... 455551638410_519345
请求执行的代码:
try:
    url = 'http://list.tmall.hk/search_product.htm?spm=a2231.7718719.2014120101.4.679012fe39jnPw&cat=51256001&auction_tag=13186&acm=lb-zebra-34359-425807.1003.8.519345&scm=1003.8.lb-zebra-34359-425807.ITEM_14455551638410_519345'
    opener = urllib.request.build_opener(HTTPCookieRedirectHandler)
    proxy_parms = {"http": "127.0.0.1:8888"}
    opener.add_handler(urllib.request.ProxyHandler(proxy_parms))
    request = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0'})
    response = opener.open(request)
    print(response.geturl())
    print(response.read().decode("utf-8", "ignore"))
except HTTPError as e:
    print(e.code)
    print(e.reason)
使用fiddler监控这次请求,发现:
请求后,它会不断重复返回302重定向,显示如下:
QQ图片20180512215553.png

最终程序报出如下错误:
302
The HTTP server returned a redirect error that would lead to an infinite loop.
The last 30x error message was:
Found


请问:我应该如何解决这个问题?

回复

使用道具 举报

0

主题

4

帖子

4

积分

贫民

积分
4
lethons 发表于 2018-5-19 20:23:08 | 显示全部楼层
可以试着取消重定向看一下
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表