37,718
社区成员
发帖
与我相关
我的任务
分享
import requests
from lxml import etree
url = 'https://www.kuaidaili.com/free'
header = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36'}
r = requests.get(url=url, headers=header).text
a = etree.HTML(r)
ip_address = a.xpath('//*[@id="list"]/table/tbody//td[@data-title="IP"]/text()')
ip_port = a.xpath('//*[@id="list"]/table/tbody//td[@data-title="PORT"]/text()')
ip_dict = dict(zip(ip_address, ip_port))
proxy = []
https = []
for key, value in ip_dict.items():
data = "http://" + key + ':' + value
proxy.append(data)
https.append('http')
print(proxy)
print(https)
proxies = dict(zip(https, proxy))
print(proxies)