from lxml import etree
import requests
headers = {
'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"
}
# 构建ip代理池
ips_list = []
url = 'http://t.11jsq.com/index.php/api/entry?method=proxyServer.generate_api_url&packid=3&fa=0&fetch_key=&groupid=0&qty=5&time=1&pro=%E6%B9%96%E5%8C%97%E7%9C%81&city=&port=1&format=html&ss=5&css=&dt=1&specialTxt=3&specialJson=&usertype=15'
page_text = requests.get(url=url, headers = headers).text
tree = etree.HTML(page_text)
ip_list = tree.xpath('//body//text()')
for ip in ip_list:
dic = {'https0':ip}
ips_list.append(dic)
# 然后我们就可以使用ips_list里面的ip了
requests.get(url='你要爬取的url',headers = '',params = '', proxies = 'ip代理池里面的ip')#格式proxies={'http':'ip:port'}