午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

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

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

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

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

代碼如下:

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(’當(dāng)前IP有效’)time.sleep(2) except Exception as e:print(e.args[0])print(’當(dāng)前IP無(wú)效’)continue

運(yùn)行結(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] 由于連接方在一段時(shí)間后沒(méi)有正確答復(fù)或連接的主機(jī)沒(méi)有反應(yīng),連接嘗試失敗。’)))當(dāng)前IP無(wú)效使用代理的IP: {’http’: ’51.158.186.242:8811’, ’https’: ’51.158.186.242:8811’}{ 'origin': '51.158.186.242'}

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

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

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

當(dāng)前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] 由于連接方在一段時(shí)間后沒(méi)有正確答復(fù)或連接的主機(jī)沒(méi)有反應(yīng),連接嘗試失敗。’)))當(dāng)前IP無(wú)效使用代理的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] 由于連接方在一段時(shí)間后沒(méi)有正確答復(fù)或連接的主機(jī)沒(méi)有反應(yīng),連接嘗試失敗。’)))當(dāng)前IP無(wú)效使用代理的IP: {’http’: ’51.158.186.242:8811’, ’https’: ’51.158.186.242:8811’}{ 'origin': '51.158.186.242'}

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

當(dāng)前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] 由于連接方在一段時(shí)間后沒(méi)有正確答復(fù)或連接的主機(jī)沒(méi)有反應(yīng),連接嘗試失敗。’)))當(dāng)前IP無(wú)效

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

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 欧美999| 一级黄色a视频 | 亚洲一区在线播放 | 欧美日韩午夜 | 欧美日本综合 | 91久久精品日日躁夜夜躁国产 | 国产精品永久免费视频 | 天堂伊人网 | 国产精品久久777777 | 国产一区二区视频在线播放 | 五月天婷婷社区 | 成人午夜av | 欧美性18 | 亚洲成人7777 | 免费黄色av| 免费黄色小视频网站 | 黄色小视频在线免费看 | 亚洲区免费视频 | 青青草97国产精品麻豆 | 韩国黄色录像 | 成人极品视频 | 国产精品久久久久久久久 | 超碰狠狠干| 欧美精品国产 | 久久精品网址 | 超碰精品 | 2014天堂网| 欧美日韩一二三 | jizz日本在线播放 | 日韩大奶子 | 亚洲一区二区三区精品视频 | 国产五月婷婷 | 久久久久久一级片 | 久久精品三级 | 国产精品999 | 日韩av片在线免费观看 | 亚洲一区免费视频 | 一区二区三区四区日韩 | 艳妇av| 国产精品一区二区不卡 | 国产美女高潮久久白浆 |