def 加载全新的IP地址():
fake = Faker(locale='zh_CN')
IP地址=[]
url='http://www.xiladaili.com/http/'
xpath='//div[@class="mt-0 mb-2 table-responsive"]/table[@class="fl-table"]/tbody/tr/td[1]/text()'
IP=换请求头爬虫(url,xpath)
for ip in IP:
op=ip.strip('\n\t\t\t')
'有些IP地址不一定有用'
proxies = {
"http": "http://{}".format(op),
"https": "https://{}".format(op)
}
headers = {
'User-Agent': fake.chrome()
}
try:
resp = requests.get('https://www.baidu.com/', headers=headers, proxies=proxies,timeout = 4)
print(IP地址)
except:
print('IP地址不可用',op)
IP地址.append(op)
print(IP地址)
return IP地址
然后,全部不能使用大概测试了一页三十个的样子。
错误是:requests.exceptions.ProxyError: HTTPConnectionPool(host='14.215.212.37', port=80): Max retries exceeded with url:
看了说明好像是电脑设置了代理什么的,请告诉我怎么解决这个问题,更改电脑设置。
```python
这些IP地址都不能使用,肯定是配置什么的错了吧。
['27.192.200.7:9000', '113.237.3.178:9999', '181.10.129.85:8080', '61.37.223.152:8080', '118.117.188.171:3256', '104.254.238.122:20171', '47.104.66.204:80', '149.5.37.113:8080', '191.101.39.193:80', '112.104.28.117:3128', '185.23.83.23:8080', '109.127.82.50:8080', '185.179.30.130:8080', '190.2.209.58:999', '218.88.204.125:3256', '178.62.56.172:80', '178.134.208.126:50824', '193.149.225.163:80', '182.87.136.228:9999', '175.42.122.142:9999', '170.83.108.69:8080', '192.109.165.128:80', '181.3.91.56:10809', '193.150.117.102:8000', '103.15.60.23:8080', '160.20.166.211:999', '47.92.252.178:3128', '182.84.144.91:3256', '118.194.242.57:80', '167.172.180.46:33555', '58.255.7.90:9999', '45.70.237.179:8080', '118.99.100.164:8080', '182.84.145.181:3256', '85.62.10.85:8080', '94.180.72.40:3128', '36.89.51.165:8080', '185.110.208.37:8080', '01.20.217.52:8080']
如果不加try:返回的错误是:
requests.exceptions.ProxyError: HTTPConnectionPool(host='193.150.117.102', port=8000): Max retries exceeded with url: http://www.haoword.com/gongzuozongjie/dangjian/677320.htm (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response')))
```