IP信誉信息查询

从ipip.net网站上查询ip的信誉信息,如基站、IDC等
查询地址:https://www.ipip.net/ip.html

代码:

import requests
from lxml import etree
import ssl
ssl._create_default_https_context = ssl._create_unverified_context

requests.packages.urllib3.disable_warnings()#忽略警告
check_ip="61.148.244.109"
url="https://www.ipip.net/ip.html"

page_headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0',
        'Connection': 'keep-alive',
        'Content-Type':'application/x-www-form-urlencoded',
        'Referer':'https://www.ipip.net/ip.html',
        'Host':'www.ipip.net',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
        'Cookie':'__jsluid=937f34ce3db5c1da1e1e85461b022399; LOVEAPP_SESSID=853504cea180e7a9aee339a505e0547cf8a6f1e6; _ga=GA1.2.1286347564.1530842494; _gid=GA1.2.734570262.1531041332'
    }

def url_open(check_ip):
    post_data={'ip':check_ip}
    res=requests.post(url,headers=page_headers,data=post_data,verify=True)
    status=res.status_code
    content=res.text
    #print(status)
    return status,content

def check_ipip(check_ip):
    status,content=url_open(check_ip)
    if status==200:
        html=etree.HTML(content)
        ip_creditL=html.xpath('//div[@class="outer tableNormal ipSearch"]//div[@class="inner"]//table[1]//tr[5]//td[1]//text()')
        if len(ip_creditL)>0:
            ip_credit=ip_creditL[0]
        else:
            ip_credit=" "
        print(ip_credit)  

check_ipip(check_ip) 

猜你喜欢

转载自blog.csdn.net/d1240673769/article/details/80964915
今日推荐