import requests
import random
import re
session = requests.session()
session.headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5)'
'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
def random_IP(IP_array):
proxies = {}
index = random.randint(0, len(IP_array) - 1)
proxies['http'] = 'http://' + IP_array[index][0] + ':' + IP_array[index][1]
print(IP_array[index][0])
return proxies
def get_new_IP():
r = session.get('http://www.xicidaili.com/nn')
IP = re.findall(r'<td>(([0-9]|\.)*)</td>', r.text)
IP_array = []
for i in range(len(IP)):
if i % 2 == 0:
IP_array.append([IP[i][0], IP[i + 1][0]])
return IP_array
IP_array = get_new_IP()
while True:
try:
r = session.get('http://ip.chinaz.com/getip.aspx', proxies=random_IP(IP_array))
print(r.text)
except Exception as e:
print(e)
自动获取免费 ip 并检测
最新推荐文章于 2024-05-11 16:13:03 发布