zoukankan      html  css  js  c++  java
  • python通过token登录,并爬取数据实例

     1 from bs4 import BeautifulSoup
     2 import requests
     3 
     4 class Zabbix(object):
     5     def __init__(self, headers):
     6         self.session = requests.Session()
     7         self.headers = headers
     8     def func(self):
     9         headers={
    10             'Host':'172.28.14.165',
    11             'Upgrade-Insecure-Requests':'1',
    12             'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
    13             'cookie':'zbx_sessionid='+token
    14         }
    15         response=self.session.get(url='http://172.28.14.165/zabbix/zabbix.php?action=report.status&ddreset=1',headers=headers,allow_redirects=False)
    16         sourse = BeautifulSoup(response.text, 'html.parser')
    17         text=sourse.find('span', {'class': 'green'})
    18         if not text :
    19             text=sourse.find('span', {'class': 'red'})
    20         tq=text.string
    21         print(tq)
    22 if __name__ == '__main__':
    23     headers = {
    24         'Host': '172.28.14.165',
    25         'Origin': 'http://172.28.14.165',
    26         'Referer':'http://172.28.14.165/zabbix/index.php',
    27         'Upgrade-Insecure-Requests':'1',
    28         'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36',
    29     }
    30     status = Zabbix(headers=headers)
    31     token=input("please input token:")
    32     status.func()
    View Code
  • 相关阅读:
    JS高阶---继承模式(原型链继承)
    一切皆数据,人生需学习
    操作系统升级
    看了跨年演讲后
    新的开始
    怎么做一名高薪前端工程师,必备哪些技术工具?
    web服务器 Nginx
    实用的软件架构方法
    购买网络自动化工具时应考虑的7个方面
    ES6 展开操作符的几个妙用
  • 原文地址:https://www.cnblogs.com/navysummer/p/8856115.html
Copyright © 2011-2022 走看看