Python爬取站长之家端口扫描接口

import requests,time
import random
from bs4 import BeautifulSoup
import re
import threading
def ports(hostm,port):
url = 'http://tool.chinaz.com/port/'
headers = {

[时间:05-01]    [浏览:]    [放入收藏夹]    [查看详情]
import requests,time
import random
from bs4 import BeautifulSoup
import re
import threading
def ports(hostm,port):
    url = 'http://tool.chinaz.com/port/'
    headers = {
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36'
    }
    data = {
        'host':hostm,
        'port':port
    }
    response = requests.post(url,headers=headers,data=data).text
    encode = BeautifulSoup(response,'html.parser').findAll('input',{"id":"encode"})[0].get('value')
    data['encode'] = encode
    callback = "jQuery113"+str(int(random.random()*100000000000000000))+'_'+str(int(time.time()*1000))
    params = {
        'callback':callback,
        't':'port'
    }
 
    url = 'http://tool.chinaz.com/iframe.ashx'
 
    response = requests.post(url,headers=headers,data=data,params=params).text
 
    response = re.sub(callback,'',response)
    print(re.findall(r"'(.*?)'",response)[0])
 
    return re.findall(r"'(.*?)'",response)[0]
 
 
if __name__=="__main__":
    for i in range(0,1000):
       # print(ports('baidu.com', str(i)))
        threading.Thread(target=ports,args=('baidu.com', str(i))).start()


  本文转载自:精准像素:11px.cn ,感谢作者分享实用知识


标签: