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
  • 相关阅读:
    内存溢出与内存泄露的区别
    <a>标签
    mac上的设置查看环境变量
    css-position
    css-overflow
    css-clear
    mongodb基本操作
    idea使用maven install命令打包(springboot),jar运行时出现没有主清单属性
    linux运行jar报错
    maven deploy时报错
  • 原文地址:https://www.cnblogs.com/navysummer/p/8856115.html
Copyright © 2011-2022 走看看