av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

Python 快速驗證代理IP是否有效的方法實現(xiàn)

瀏覽:128日期:2022-06-15 08:22:32

有時候,我們需要用到代理IP,比如在爬蟲的時候,但是得到了IP之后,可能不知道怎么驗證這些IP是不是有效的,這時候我們可以使用Python攜帶該IP來模擬訪問某一個網(wǎng)站,如果多次未成功訪問,則說明這個代理是無效的。

代碼如下:

import requestsimport randomimport timehttp_ip = [ ’118.163.13.200:8080’, ’222.223.182.66:8000’, ’51.158.186.242:8811’, ’171.37.79.129:9797’, ’139.255.123.194:4550’]for i in range(10): try:ip_proxy = random.choice(http_ip)proxy_ip = { ’http’: ip_proxy, ’https’: ip_proxy,}print(’使用代理的IP:’, proxy_ip)response = requests.get('http://httpbin.org/ip', proxies=proxy_ip).textprint(response)print(’當前IP有效’)time.sleep(2) except Exception as e:print(e.args[0])print(’當前IP無效’)continue

運行結(jié)果如下:

使用代理的IP: {’http’: ’118.163.13.200:8080’, ’https’: ’118.163.13.200:8080’}HTTPConnectionPool(host=’118.163.13.200’, port=8080): Max retries exceeded with url: http://httpbin.org/ip (Caused by ProxyError(’Cannot connect to proxy.’, NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x00000247674F5F88>: Failed to establish a new connection: [WinError 10060] 由于連接方在一段時間后沒有正確答復(fù)或連接的主機沒有反應(yīng),連接嘗試失敗。’)))當前IP無效使用代理的IP: {’http’: ’51.158.186.242:8811’, ’https’: ’51.158.186.242:8811’}{ 'origin': '51.158.186.242'}

當前IP有效使用代理的IP: {’http’: ’222.223.182.66:8000’, ’https’: ’222.223.182.66:8000’}{ 'origin': '139.202.62.84, 222.223.182.66'}

當前IP有效使用代理的IP: {’http’: ’51.158.186.242:8811’, ’https’: ’51.158.186.242:8811’}{ 'origin': '51.158.186.242'}

當前IP有效使用代理的IP: {’http’: ’51.158.186.242:8811’, ’https’: ’51.158.186.242:8811’}{ 'origin': '51.158.186.242'}

當前IP有效使用代理的IP: {’http’: ’222.223.182.66:8000’, ’https’: ’222.223.182.66:8000’}HTTPConnectionPool(host=’222.223.182.66’, port=8000): Max retries exceeded with url: http://httpbin.org/ip (Caused by ProxyError(’Cannot connect to proxy.’, NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x00000247675067C8>: Failed to establish a new connection: [WinError 10060] 由于連接方在一段時間后沒有正確答復(fù)或連接的主機沒有反應(yīng),連接嘗試失敗。’)))當前IP無效使用代理的IP: {’http’: ’139.255.123.194:4550’, ’https’: ’139.255.123.194:4550’}HTTPConnectionPool(host=’139.255.123.194’, port=4550): Max retries exceeded with url: http://httpbin.org/ip (Caused by ProxyError(’Cannot connect to proxy.’, NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x00000247674F55C8>: Failed to establish a new connection: [WinError 10060] 由于連接方在一段時間后沒有正確答復(fù)或連接的主機沒有反應(yīng),連接嘗試失敗。’)))當前IP無效使用代理的IP: {’http’: ’51.158.186.242:8811’, ’https’: ’51.158.186.242:8811’}{ 'origin': '51.158.186.242'}

當前IP有效使用代理的IP: {’http’: ’51.158.186.242:8811’, ’https’: ’51.158.186.242:8811’}{ 'origin': '51.158.186.242'}

當前IP有效使用代理的IP: {’http’: ’222.223.182.66:8000’, ’https’: ’222.223.182.66:8000’}HTTPConnectionPool(host=’222.223.182.66’, port=8000): Max retries exceeded with url: http://httpbin.org/ip (Caused by ProxyError(’Cannot connect to proxy.’, NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x0000024767514908>: Failed to establish a new connection: [WinError 10060] 由于連接方在一段時間后沒有正確答復(fù)或連接的主機沒有反應(yīng),連接嘗試失敗。’)))當前IP無效

到此這篇關(guān)于Python 快速驗證代理IP是否有效的方法實現(xiàn)的文章就介紹到這了,更多相關(guān)Python 驗證代理IP是否有效內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 永久黄网站色视频免费观看w | 国产成人免费在线视频 | 精品一区二区三区免费 | 欧美一区在线视频 | 日韩欧美在线看 | 91欧美大片 | 巨骚综合| 日韩精品一区二区视频 | www国产亚洲精品久久网站 | 久久人人爽人人爽人人片 | 亚洲男人网| 亚洲成人国产 | 国产自在线 | 中国黄色1级片 | 91网站免费 | 欧美性猛交99久久久久99按摩 | 日本精品视频 | 国产精品免费人成网站酒店 | 成人精品免费视频 | 九色在线观看 | 精品国产乱码久久久久久蜜臀网站 | 日韩免费一区二区三区 | 91一区二区 | 天天干天天干天天 | 日韩欧美一区二区三区久久婷婷 | 欧美视频一区二区三区 | 双性呜呜宫交受不住了h | 黄色特级片 | 丁香色婷婷| 中文字幕在线免费 | 婷婷久久五月天 | 91精品国自产在线观看 | 久久98 | a在线播放| 国产精品网站在线观看 | 亚洲少妇一区 | 亚洲视频在线看 | 国产成人一区 | 在线观看日韩欧美 | 免费国产精品视频 | 欧美精品日韩少妇 |