描述
zabbix无法批量筛选不可用的主机,所以写出python爬虫取相关信息,在桌面会生成一个txt,在excel导入以","分隔即可!
import requests,time,re,csv
headers={
"Host":"monitor.xurikeji.com",
"Referer":"https://monitor.xurikeji.com/zabbix.php?action=dashboard.view",
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0",
"Cookie":"PHPSESSID=hstu9k7d28adbeqpl6bxyzd2o0; zbx_sessionid=8f281cd98165b093511e072212ds1025f2"
}
obj=re.compile(r'<tr><td><input.*?<a href=.*?>(?P<name>.*?)</a>.*?<a href="httpconf\.php.*?</td><td>(?P<ip>.*?)</td><td>(?P<proxy>.*?)</td><td>.*?class="status-container"><span class="(?P<status>.*?)"',re.S)
with open(r'D:\xuri-1.1\桌面\text.txt', 'a', encoding='UTF8') as f:
for i in range(1,15):
url="https://monitor.xurikeji.com/hosts.php?groupid=0&page="+str(i)
response=requests.get(url,headers=headers)
response.encoding = 'utf-8'
source=response.text
res=obj.finditer(source)
for i in res:
f.write(i.group('name')+","+i.group('ip')+","+i.group('proxy')+","+i.group('status')+"\n")
print(i.group('name')+","+i.group('ip')+","+i.group('proxy'))
# coding:utf-8
import requests,time,re,csv
headers={
"Host":"monitor.xurikeji.com",
"Referer":"https://monitor.xurikeji.com/zabbix.php?action=dashboard.view",
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0",
"Cookie":"PHPSESSID=k4a45anbtarqiuiojcrcobbki5; zbx_sessionid=2c620c08f46ec098e971a64f7759bcb6"
}
#obj=re.compile(r'<tr><td><input.*?<a href=.*?>(?P<name>.*?)</a>.*?<a href="httpconf\.php.*?</td><td>(?P<ip>.*?)</td><td>(?P<proxy>.*?)</td><td>.*?class="status-container"><span class="(?P<status>.*?)"',re.S)
obj=re.compile(r'<tr><td><input.*?<a href=.*?>(?P<name>.*?)</a>.*?<a href="httpconf\.php.*?</td><td>(?P<ip>.*?)</td><td>(?P<proxy>.*?)</td><td>.*?href="javascript:void\(0\)">(?P<startstop>.*?)</a></td>.*?<div class="status-container"><span class="(?P<status>.*?)">',re.S)
with open(r'C:\Users\xurikejio\Desktop\text.txt', 'a', encoding='UTF8') as f:
# url = "https://monitor.xurikeji.com/hosts.php?groupid=0&page=1"
# response = requests.get(url, headers=headers)
# response.encoding = 'utf-8'
# source = response.text
# res=obj.finditer(source)
# for i in res:
# #f.write(i.group('name')+","+i.group('ip')+","+i.group('proxy')+","+i.group('status')+"\n")
# print(i.group('name')+","+i.group('ip')+","+i.group('proxy')+","+i.group('startstop')+","+i.group('status'))
for i in range(1,19):
url="https://monitor.xurikeji.com/hosts.php?groupid=0&page="+str(i)
response=requests.get(url,headers=headers)
response.encoding = 'utf-8'
source=response.text
res=obj.finditer(source)
for i in res:
f.write(i.group('name')+","+i.group('ip')+","+i.group('proxy')+","+i.group('startstop')+","+i.group('status')+"\n")
print(i.group('name')+","+i.group('ip')+","+i.group('proxy')+","+i.group('startstop')+","+i.group('status'))