温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

东拼西凑用python脚本登录web管理页面做巡检(函数实现)

发布时间:2020-07-25 10:47:39 来源:网络 阅读:324 作者:biltmore 栏目:编程语言

import datetime

import selenium

from selenium import webdriver

from selenium.webdriver.chrome.options import Options

from time import sleep

from pyquery import PyQuery as pq


db_cell_host=["https://192.40.0.6/iPages/i_login.asp","https://192.40.0.7/iPages/i_login.asp","https://192.40.0.8/iPages/i_login.asp","https://192.40.0.9/iPages/i_login.asp","https://192.40.0.10/iPages/i_login.asp",      "https://192.40.1.6/iPages/i_login.asp","https://192.40.1.7/iPages/i_login.asp","https://192.40.1.8/iPages/i_login.asp","https://192.40.1.9/iPages/i_login.asp","https://192.40.1.10/iPages/i_login.asp"]


ib_host=["https://192.40.0.12","https://192.40.0.13",

      "https://192.40.1.12","https://192.40.1.13"]

'''

def __init__():

xunjian(host)

'''   

def xunjian1(arg1=[]):   

opt = webdriver.ChromeOptions()

opt.set_headless()

browser = webdriver.Chrome(options=opt)   

for url in arg1:

browser.get(url)

browser.find_element_by_id("username").send_keys("admin")

browser.find_element_by_id("password").send_keys("Passw0rd")

browser.find_element_by_id("loginButton").click()

sleep(1)

browser.switch_to.frame('mainFrame')

# sleep(1)

browser.switch_to.frame('treeFrame')


selenium_html = browser.execute_script("return document.documentElement.outerHTML")

doc = pq(selenium_html)

dochtml = doc('a[id="Open_Problems_anchor"]')

strSources = dochtml.text().encode('utf8').strip()

txtsource = strSources[strSources.find('Open Problems') + 0:]

print (datetime.datetime.now().strftime('%m-%d %H;%M:%S'),url,txtsource)


browser.close()


def xunjian2(arg1=[]):

        opt = webdriver.ChromeOptions()

        opt.set_headless()

        browser = webdriver.Chrome(options=opt)

        for url in arg1:

                url = url + "/iPages/i_indicators.asp"

                browser.get(url)

                browser.find_element_by_id("username").send_keys("admin")

                browser.find_element_by_id("password").send_keys("Passw0rd")

                browser.find_element_by_id("button").click()


                browser.get(url)

                selenium_html = browser.execute_script("return document.documentElement.outerHTML")

                doc = pq(selenium_html)

                dochtml =doc('tr[id="ht_TblIndicators_Row1"]')

                strSources =dochtml.text().encode('utf8').strip()

                txtsource = strSources[strSources.find('-') + 0:]

                print (datetime.datetime.now().strftime('%m-%d %H;%M:%S'),url,txtsource)

        browser.close()


xunjian1(db_cell_host)

xunjian2(ib_host)


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI