Does urllib2.urlopen() cache stuff?

后端 未结 5 1731
渐次进展
渐次进展 2020-12-17 16:35

They didn\'t mention this in python documentation. And recently I\'m testing a website simply refreshing the site using urllib2.urlopen() to extract certain content, I notic

5条回答
  •  一向
    一向 (楼主)
    2020-12-17 17:15

    Your web server or an HTTP proxy may be caching content. You can try to disable caching by adding a Pragma: no-cache request header:

    request = urllib2.Request(url)
    request.add_header('Pragma', 'no-cache')
    content = urllib2.build_opener().open(request)
    

提交回复
热议问题