Proxy Check in python

后端 未结 4 458
既然无缘
既然无缘 2020-12-23 14:55

I have written a script in python that uses cookies and POST/GET. I also included proxy support in my script. However, when one enters a dead proxy, the script crashes. Is t

4条回答
  •  萌比男神i
    2020-12-23 15:52

    There is one nice package Grab So, if it ok for you, you can write something like this(simple valid proxy checker-generator):

    from grab import Grab, GrabError
    
    def get_valid_proxy(proxy_list): #format of items e.g. '128.2.198.188:3124'
        g = Grab()
        for proxy in proxy_list:
            g.setup(proxy=proxy, proxy_type='http', connect_timeout=5, timeout=5)
            try:
                g.go('google.com')
            except GrabError:
                #logging.info("Test error")
                pass
            else:
                yield proxy
    

提交回复
热议问题