需要请求的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


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

举报 使用道具
| 回复

共 1 个关于本帖的回复 最后回复于 2018-5-13 09:43

Fuller 管理员 发表于 2018-5-13 09:43:38 | 显示全部楼层
像天猫这样的电商,一个网址一般会做跳转,因为他们要收集访客行为或者广告效果评估。所以,网络爬虫一定要处理重定向。

不过,根据你的截图看,应该是重定向到登录页面了,要求你做登录,那就要用程序做模拟登录过程
举报 使用道具
您需要登录后才可以回帖 登录 | 立即注册

精彩推荐

  • Gephi社会网络分析-马蜂窝游记文本分词并同
  • Gephi社会网络分析-基于马蜂窝游记文本以词
  • 知乎话题文本根据词语间距筛选后生成共词矩
  • 马蜂窝游记文本分词后以词语间距为筛选条件
  • 学习使用apriori算法挖掘关联关系

热门用户

GMT+8, 2024-3-29 17:17