import requests
import pandas
from lxml import etree
ip_table=pandas.read_excel('ip.xlsx')
ip = ip_table['ip']
headers ={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'}for i in ip:
proxies ={'http':'http://{ip}'.format(ip=i),'https':'http://{ip}'.format(ip=i)}try:
response = requests.get('http://202020.ip138.com/',headers=headers,proxies=proxies,timeout=2)if response.status_code==200:
response.encoding='utf-8'
html = etree.HTML(response.text)
info = html.xpath('/html/body/p[1]//text()')print(info)except Exception as e:print('错误异常信息为:',e)