python requests is slow

前端 未结 2 1431
滥情空心
滥情空心 2020-12-10 18:55

I am developing a download manager. Using the requests module in python to check for a valid link (and hopefully broken links). My code for checking link below:



        
相关标签:
2条回答
  • 2020-12-10 19:23

    Not all hosts support head requests. You can use this instead:

    r = requests.get(url, stream=True)
    

    This actually only download the headers, not the response content. Moreover, if the idea is to get the file afterwards, you don't have to make another request.

    See here for more infos.

    0 讨论(0)
  • 2020-12-10 19:45

    Don't use get that actually retrieves the file, use:

    r = requests.head(url,allow_redirects=False)
    

    Which goes from 6.9secs on my machine to 0.4secs

    0 讨论(0)
提交回复
热议问题