Python urllib3 and how to handle cookie support?

后端 未结 5 887
野趣味
野趣味 2020-12-06 16:55

So I\'m looking into urllib3 because it has connection pooling and is thread safe (so performance is better, especially for crawling), but the documentation is... minimal to

5条回答
  •  醉梦人生
    2020-12-06 17:45

    You can use a code like this:

    def getHtml(url):
        http = urllib3.PoolManager()
        r = http.request('GET', url, headers={'User-agent':'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.16 Safari/537.36','Cookie':'cookie_name=cookie_value'})
        return r.data #HTML
    

    You should replace cookie_name and cookie_value

提交回复
热议问题