python3.5 urllib.request 怎么禁止301,302跳转

willhuo 2015-12-01 04:48:54
咱们这里人好少。。。。
我查了很多材料,就是没人见人实现过,怎么禁止重定向
...全文
627 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
willhuo 2015-12-24
  • 打赏
  • 举报
回复
引用 1 楼 nice_fish 的回复:
http://www.diveintopython.net/http_web_services/redirects.html 这个应该就是你要的示例了。
貌似不怎么管用了,我设置了以后。。。。
  • 打赏
  • 举报
回复


class SmartRedirectHandler(urllib2.HTTPRedirectHandler):     1
    def http_error_301(self, req, fp, code, msg, headers):  
        result = urllib2.HTTPRedirectHandler.http_error_301( 2
            self, req, fp, code, msg, headers)              
        result.status = code                                 3
        return result                                       

    def http_error_302(self, req, fp, code, msg, headers):   4
        result = urllib2.HTTPRedirectHandler.http_error_302(
            self, req, fp, code, msg, headers)              
        result.status = code                                
        return result      

  • 打赏
  • 举报
回复
http://www.diveintopython.net/http_web_services/redirects.html 这个应该就是你要的示例了。

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧