How do I set cookies using Python urlopen?

前端 未结 1 705
逝去的感伤
逝去的感伤 2021-02-06 18:15

I am trying to fetch an html site using Python urlopen.
I am getting this error:

HTTPError: HTTP Error 302: The HTTP server returned a redirect error

相关标签:
1条回答
  • 2021-02-06 18:20

    Here's an example from Python documentation, adjusted to your code:

    import cookielib, urllib2
    cj = cookielib.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    request = urllib2.Request(url)
    response = opener.open(request)
    
    0 讨论(0)
提交回复
热议问题