感谢大家的帮助
本帖最后由 Vastsea 于 2020-5-20 12:08 编辑第一次写代码,感谢大家的帮助,我觉得还有很多需要优化的地方。请大家指教一下。谢谢!
背景:我们租用了十几台打印机每月都要抄打印机的印数。因为是网络打印机又都有WEB管理界面,所以想到通过Python自动抄录的想法。
import requests
from bs4 import BeautifulSoup
from openpyxl import Workbook
wb = Workbook()
ws = wb.active
ws['A1'] = "IP地址"
ws['B1'] = "总数"
n = 2
ip1 = ['10.0.3.12','10.0.55.20','10.0.3.18','10.0.70.18','10.0.3.15','10.0.70.20','10.0.70.24','10.0.60.70']
for i in ip1:
url1 = "http://" + i + "/web/guest/cn/websys/status/getUnificationCounter.cgi"
req = requests.get(url1)
html = req.text
bs = BeautifulSoup(html,"html.parser")
trs = bs.select('tr.staticProp').get_text()
r = str(n)
n = n + 1
ws['a' + r] = i
ws['b' + r] = trs
wb.save("C:\\New folder\\11.xlsx")
n = 10
ip2 = ['10.0.3.30','10.0.3.31','10.0.3.32','10.0.65.18','10.0.70.22','10.0.65.11','10.0.45.11']
for j in ip2:
url2 = "http://" + j + "/SSI/info_configuration.htm"
req = requests.get(url2)
html = req.text
bs = BeautifulSoup(html,"html.parser")
trs = bs.select('tr').get_text()
r = str(n)
n = n + 1
ws['a' + r] = j
ws['b' + r] = trs.strip()
wb.save("C:\\New folder\\11.xlsx") 1.请发提问帖
2.我们没有管理界面,帮不了你。 永恒的蓝色梦想 发表于 2020-5-20 12:00
1.请发提问帖
2.我们没有管理界面,帮不了你。
改了 本帖最后由 永恒的蓝色梦想 于 2020-5-20 12:44 编辑
Vastsea 发表于 2020-5-20 12:08
改了
并没有
呐……好像是缓存的原因{:10_277:}
页:
[1]