好友
阅读权限10
听众
最后登录1970-1-1
|
本帖最后由 hahawangzi 于 2020-9-14 11:11 编辑
想写一个运维脚本,python自动登录打印机后台(网页方式),查看里面的墨粉及其他消耗品情况。
后台登录进去会有一个alert提示消息,按掉以后想定位到 消耗品这个link_text但是定位不到。
* coding="utf-8" *
import sys,re,os
import requests
import json,time
from bs4 import BeautifulSoup
from selenium import webdriver
--------------------------------------------
driver = webdriver.Chrome()
driver.get("http://11111:x-admin@10.197.196.111")
alert=driver.switch_to_alert()
time.sleep(2)
alert.accept()
time.sleep(5)
driver.switch_to_frame(1)
print(driver.page_source)
driver.find_element_by_name("NF")
print(str(driver.page_source))
因为处于两个frame里面 所有我也切换了frame,但是还是不行
这里是网页的源码
后来我又取了一下源码看到 是这样的。可能是JS加载后才能显现出来的源码,这该如何是好?
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
Internet Services
</title>
<script language="JavaScript1.2"><!--
var nvTree=[];
var trItms=[];
var csItms=[];
var biItms=[];
var cap='状态';
var sdown='关闭';
var sup='打开';
var chSet='UTF-8';
var ico='devtiny';
var rInt=120;
nvTree[nvTree.length]=['d','常规','stgen'];
nvTree[nvTree.length]=['d','纸盘','sttray'];
nvTree[nvTree.length]=['d','消耗品','stsply'];
biItms[biItms.length]=['d','计数器显示','prcnt'];
nvTree[nvTree.length]=['f','计数', biItms];
nvTree[nvTree.length]=['d','各运行状况的累计时间','timecnt'];
var safeTipsKO =['安全性警告','为保证机器的安全性,请变更以下设定的默认状态。','机器管理员识别符/机器管理员密码','详情请参阅《使用说明书》。'];
var safeTipsGIP =['安全性警告','本机器上设定了全局IP地址。','在设定了全局IP地址的情况下,可能会被从外部非法存取。','请确认网络设定。','详情请参阅《使用说明书》。'];
var safeTipsSNMP =['安全性信息','以下设定处于默认状态。','SNMP团体名称/认证密码','详情请参阅《使用说明书》。'];
var warningInfo=[1,0,1];
if(warningInfo.length == 3){
if(warningInfo[0]) {
popup(safeTipsKO);
}
if(warningInfo[1]) {
popup(safeTipsGIP);
}
if(warningInfo[2]) {
popup(safeTipsSNMP);
}
}
var rFrm=2;
var loc='stgen';
var hdrname='hdstat.htm';
var rTmr=null;
var rSec;
var isNN=false;
var isIE=false;
var jtPath = '/jt/cgi-bin/';
var sHtml = location.href.substr(location.href.lastIndexOf('/')+1);
var isScan = sHtml.indexOf('scan.htm')?0:1;
var isProp = sHtml.indexOf('prop.htm')?0:1;
if (document.all) isIE=true; else if (navigator.appName=="Netscape"&&navigator.userAgent.indexOf("Opera", 0)==-1) isNN=true;
function disp() {
reset_cgi();
if (loc.indexOf('.cgi') < 0){
frames[rFrm].window.location.href=loc+'.htm';
if (isScan && isJt)
frames[2].window.location.href='blank.htm';
}
else{
if (isScan){
frames[2].window.location.href=jtPath + loc;
}
else{
frames[rFrm].window.location.href=jtPath + loc;
}
}
if (isProp) clr_all();
}
function refIE() {clearTimeout(rTmr); if (--rSec>0) rTmr=setTimeout('refIE()', 1000); else {rTmr=null; disp();}}
function refNN() {if (rTmr!=null && --rSec<=0) {clearInterval(rTmr); rTmr=null; disp();}}
function doRef() {
if (rInt<=0) return;
if (rTmr!=null) if (isNN) clearInterval(rTmr); else clearTimeout(rTmr);
rSec=rInt;
rTmr=(isNN)? setInterval('refNN()', 1000): setTimeout('refIE()', 1000);
}
function undoRef() {
if (!rInt || rTmr==null) return;
if (isNN) clearInterval(rTmr); else clearTimeout(rTmr);
rTmr=null;
}
function drawBlankpage(f) {
frames[f].window.document.open();
frames[f].window.document.writeln('<HTML><HEAD><META http-equiv="Content-Type" content="text/html; charset=', chSet, '"></HEAD>');
frames[f].window.document.writeln('<BODY rightmargin="0" bgcolor="#D1D8E8">');
frames[f].window.document.writeln('</BODY></HTML>');
frames[f].window.document.close();
}
function zeros(n) {var z=new Array(n); for (var i=0; i<n; i++) z=0; return z;}
function fflip(i, j) {
if (j>=0 && j<nvTree[2].length) {if(nvFol[j]!=0) nvFol[j]=0; else nvFol[j]=1;}
else nvFol=nvFol?0:1;}
var nvSel=[0,0,0];
var nvFol=zeros(nvTree.length);
function dclick(i, j, k) {
if (nvTree[0]!='f') {loc=nvTree[2];}
else if (j>=nvTree[2].length) return;
else if (nvTree[2][j][0]!='f') {loc=nvTree[2][j][2];}
else if (k>=nvTree[2][j][2].length) return;
else {loc=nvTree[2][j][2][k][2];}
reset_cgi();
nvSel=[i, j, k];
if (loc.indexOf('.cgi') < 0) { /*画面が表示の場合*/
frames[rFrm].window.location.href=loc+'.htm';/*右側のframeを描く*/
if (isScan)/*スキャンタブなら、左下frame(N2)に空画面を描く*/
drawBlankpage(2);
}
else{ /*EWS-JTの画面が表示場合*/
if (isScan) {
/*スキャンタブで、EWS-JT画面を左下frame(N2)に表示*/
frames[2].window.location.href=jtPath + loc;
}
else {
/*他にタブで、EWS-JT画面を右側frame(R)に表示*/
frames[rFrm].window.location.href=jtPath + loc;
}
}
}
function redrawTree() {drawTree(1);}
function drawTree(f) {
var sp=(isIE)? frames[f].window.document.body.scrollTop: frames[f].pageYOffset;
frames[f].window.document.open();
frames[f].window.document.writeln('<HTML><HEAD><META http-equiv="Content-Type" content="text/html; charset=', chSet, '"></HEAD>');
frames[f].window.document.writeln('<BODY rightmargin="0" bgcolor="#D1D8E8" link="#333333" alink="#333333" vlink="#333333">');
frames[f].window.document.writeln('<TABLE bgcolor="black" border="0" cellspacing="0" cellpadding="0" width="233" vspace="6" hspace="0">');
frames[f].window.document.writeln('<TR><TD><TABLE border="0" width="100%" cellspacing="1" cellpadding="0" ><TR bgcolor="#646A8C" align="left">');
frames[f].window.document.writeln('<TD style="text-indent : 1em"><B><FONT size="-1" color="white">', cap, '</FONT></B></TD></TR></TABLE><TR><TD>');
wrTree(f);
frames[f].window.document.writeln('</TABLE></TD></TR></TABLE>')
frames[f].window.document.writeln('</BODY></HTML>');
frames[f].window.document.close();
if (sp) frames[f].window.scrollTo(0, sp);
}
function wrRs(f) {
frames[f].window.document.writeln('<TR><TD><TABLE border="0" cellspacing="0" cellpadding="0" width="100%"><TR>');
}
function wrRe(f) {
frames[f].window.document.writeln('</TR></TABLE></TD></TR>');
}
function wrAIco(f, g, m, a) {
frames[f].window.document.writeln('<TD nowrap bgcolor="#8890b1">', a, '<IMG src="I/', g, '.gif" border="0" width="18" height="18" alt="', m, '"></A></TD>');
}
function wrAIco2(f, g, m, a) {
frames[f].window.document.writeln('<TD nowrap>', a, '<IMG src="I/', g, '.gif" border="0" width="18" height="18" alt="', m, '"></A></TD>');
}
function wrAlbl(f, s, a) {
frames[f].window.document.writeln('<TD nowrap>', a, '<FONT size="2">', s, '</FONT></A></TD>');
}
function wrBlbl(f, s, a) {
frames[f].window.document.writeln('<TD nowrap bgcolor="#8890b1" width="100%">', a, '<FONT size="2" color="white">', s, '</A></FONT></TD>');
}
function wrBlbl2(f, s, a) {
frames[f].window.document.writeln('<TD nowrap bgcolor="#8890b1" width="100%">', a, '<FONT size="2" color="white">', s, '</A></FONT></TD>');
}
function wrPad(f) {
frames[f].window.document.writeln('<TD width="18" height="20"><IMG src="I/pad.png" border="0" width="18" height="20" alt=""></TD>');
}
function wrPad2(f) {
frames[f].window.document.writeln('<TD nowrap bgcolor="#8890b1" width="18" height="20"><IMG src="I/pad.png" border="0" width="18" height="20" alt=""></TD>');
}
function wrBorder(f,o) {
frames[f].window.document.writeln('<TR><TD>', o, '</TD></TR>');
}
function wrLbl(f, a, s) {
frames[f].window.document.writeln('<TD nowrap width="100%"><B><FONT size="2">', a, s, '</FONT></B></A></TD>');
}
function wrItm(f, itm, b, i, j, k) {
var a='<A href="JavaScript:parent.dclick('+i+','+j+','+k+');parent.redrawTree();" style="text-decoration:none">';
if (b) {
wrPad2(f);
wrBlbl(f, itm[1], a);}
else {
wrPad(f);
wrAlbl(f, itm[1], a);}
}
function wrFol(f, i, j) {
var a = '<A href="JavaScript:parent.fflip('+i+');parent.redrawTree();">';
var g='closed'; var m=sup; if (j==-1) {if (nvFol) {g='open'; m=sdown;}} else {if (nvFol[j]) {g='open'; m=sdown;}}
if (j==-1) {
if (nvFol) {g='open'; m=sdown;}
}
else {
if (nvFol[j]) {g='open'; m=sdown;}
}
if(g=='closed' && j>0) {wrAIco(f, g, m, a);}
else {wrAIco2(f, g, m, a);}
}
function wrOpFol(f, a, s) {
frames[f].window.document.writeln('<TD nowrap width="100%"><B><FONT size="2">', a, s, '</FONT></B></A></TD>');
}
function wrClFol(f, a, s) {
frames[f].window.document.writeln('<TD nowrap width="100%"><B><FONT size="2">', a, s, '</FONT></B></A></TD>');
}
function bgnTblTree(f) {
frames[f].window.document.writeln('<TABLE border="0" cellspacing="0" cellpadding="0" bgcolor="#646A8C" width="100%"><TR><TD>');
frames[f].window.document.writeln('<TABLE border="0" cellspacing="1" cellpadding="0" width="100%"><TR><TD>');
frames[f].window.document.writeln('<TABLE border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" width="100%"><TR><TD>');
}
function endTblTree(f) {frames[f].window.document.writeln('</TD></TR></TABLE></TD></TR></TABLE></TD></TR></TABLE>');}
function wrTree(f) {
var o='<p style="border-width:thin; border-color:#DCDCDC; border-style:solid;"></p>';
bgnTblTree(f);
frames[f].window.document.writeln('</TD></TR></TABLE>');
frames[f].window.document.writeln('<TABLE border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" width="100%"><TR><TD>');
for (var i = 0; i < nvTree.length; i++) {
if (nvTree[0]!='f') {wrRs(f); wrItm(f, nvTree, i==nvSel[0], i, 0, 0); wrRe(f);}
else {
wrBorder(f,o);
if (nvFol) {
wrRs(f); wrFol(f, i, -1);
var a='<A href="JavaScript:parent.fflip('+i+');parent.redrawTree();" style="text-decoration:none">';
wrOpFol(f, a, nvTree[1]); wrRe(f);
for (var j=0; j<nvTree[2].length; j++) {
if(nvTree[2][j][0]!='f') {
wrRs(f);
if (i==nvSel[0] && j==nvSel[1]) wrPad2(f);
else wrPad(f);
wrItm(f, nvTree[2][j], i==nvSel[0] && j==nvSel[1], i, j, 0);wrRe(f);}
else {
if (nvFol.length!=nvTree[2].length) {
nvFol=zeros(nvTree[2].length);
}
wrRs(f);
if (i>nvTree.length-1) wrPad(f);
wrFol(f, i, j); wrLbl(f, nvTree[2][j][1]); wrRe(f);
if (nvFol[j]) {
for (var k=0; k<nvTree[2][j][2].length; k++) {
wrRs(f);
if (i>nvTree.length-1) wrPad(f);
if (j>nvTree[2].length-1) wrPad(f);
wrItm(f, nvTree[2][j][2][k], i==nvSel[0] && j==nvSel[1] && k==nvSel[2], i, j, k);
wrRe(f);
}}}}}
else { wrRs(f);
var a='<A href="JavaScript:parent.fflip('+i+');parent.redrawTree();" style="text-decoration:none">';
if (i==nvSel[0]) {wrFol(f, i, 1); wrBlbl2(f, nvTree[1], a);}
else { var a='<A href="JavaScript:parent.fflip('+i+');parent.redrawTree();" style="text-decoration:none">';
wrFol(f, i, 0);
wrClFol(f, a, nvTree[1]);
}
wrRe(f);}}}
endTblTree(f);
}
function popup(tipsname) {
var mes;
for (var i=0; i<tipsname.length; i++) {
if (i==0){
mes = tipsname+':'+'\n';
}
else if (i==(tipsname.length-1)){
mes += '\n\n'+tipsname;
}
else {
mes += '\n'+tipsname;
}
}
alert(mes);
return 0;
}
var cgiArray = 10;
var saved_params = null;
var saved_cgi_params = new Array(cgiArray);
for (var i=0; i<cgiArray; i++) {saved_cgi_params = null;}
function saved_key(obj, form) {
for (var key = 0; key < form.length; key++) {
var type_str = form.elements[key].type;
var name_str = form.elements[key].name;
if (type_str == "text" || type_str == "textarea" || type_str == "hidden" || type_str == "password") {
if (name_str) {
obj[name_str] = form.elements[name_str].value;
}
else {
obj[key] = form.elements[key].value;
}
}
else if (type_str == "checkbox") {
if (name_str) {
obj[name_str] = (form.elements[key].checked)? 1: 0;
}
else {
obj[key] = (form.elements[key].checked)? 1: 0;
}
}
else if (type_str == "radio") {
if (form.elements[key].checked) {obj[name_str] = key;}
}
else if (type_str == "select-one") {
obj[name_str] = form.elements[key].selectedIndex;
}
else if (type_str == "select-multiple") {
var sel = new Array();
for (var i = 0; i < form.elements[key].options.length; i++) {
if (form.elements[key].options.selected)
sel[sel.length] = i;
}
obj[name_str] = sel;
}
else if (!type_str && form.elements[key].length) {
var type_str_0 = form.elements[key][0].type;
if (type_str_0 == "checkbox") {
var chk = new Array();
for (var i = 0; i < form.elements[key].length; i++ ) {
if (form.elements[key].checked)
chk[chk.length] = i;
}
obj[name_str] = chk;
}
else if (type_str_0 == "radio") {
for (var i = 0; i < form.elements[key].length; i++) {
if (form.elements[key].checked) {
obj[name_str] = i;
break;
}
}
}
}
}
}
function apply_changes(form, key_html) {
var obj = new Object;
obj.time_stamp = (new Date()).getTime();
obj.source_html = key_html;
saved_key(obj, form);
top.saved_params = obj;
}
function apply_cgi_params(form, key_html) {
var i;
var obj = new Object;
obj.source_html = key_html;
obj.cgi_action = form.action;
saved_key(obj, form);
for (i = 0; i < cgiArray; i++) {
if (top.saved_cgi_params == null) {break;}
if (top.saved_cgi_params.cgi_action == obj.cgi_action) {
break;
}
}
top.saved_cgi_params = obj;
}
function chkBrowserVersion(s) {
var browser = navigator.appVersion;
var index = browser.indexOf(s, 0);
if (index >= 0) return browser.substring(index + s.length, index + s.length +4);
return -1;
}
function Sleep(t) {
var t1 = new Date().getTime();
var t2 = new Date().getTime();
while (t2 < t1+t) {t2 = new Date().getTime();}
}
function restore_saved_params(form, key_html) {
if (isIE) {
var version = parseInt(chkBrowserVersion("MSIE"));
if (version > 0 && version < 6) Sleep(100);
}
if (top.saved_params != null && top.saved_params.source_html == key_html) {
if ((new Date()).getTime() - top.saved_params.time_stamp < 180000) {
for (var i = 0; i < form.length; i++) {
var fname=form.elements.name;
var ftype=form.elements.type;
if ((top.saved_params == null && top.saved_params[fname] == null) || ftype == "button" || ftype == "reset") {
continue;
}
if (ftype == "checkbox") {
if (fname) form.elements.checked = (top.saved_params[fname])?true:false;
else form.elements.checked = (top.saved_params)?true:false;
}
else if (ftype == "select-one") {
form.elements.selectedIndex = top.saved_params[fname];
}
else if (ftype == "password") {
if (form.elements.defaultValue != top.saved_params[fname]) {
form.elements.value = '';
}
}
else if (ftype == "radio") {
if (fname && top.saved_params[fname] != null && (top.saved_params[fname] == i)) {
form.elements.checked = true;
}
}
else {
if (fname) form.elements.value = top.saved_params[fname];
else form.elements.value = top.saved_params;
}
}
}
top.saved_params = null;
}
}
function reset_cgi() {
saved_params = null;
for (var i = 0; i < cgiArray; i++) {
if (top.saved_cgi_params == null) {break;}
top.saved_cgi_params = null;
}
}
//--></script>
</head>
<frameset frameborder="0" border="0" rows="89,*">
<frame name="TF" scrolling="no" noresize="" src="hdstat.htm">
<frameset frameborder="0" border="0" cols="263,*">
<frame name="NF" scrolling="auto" noresize="" src="nvtree.htm">
<frameset frameborder="0" border="0" rows="*,125">
<frame name="RF" scrolling="auto" src="stgen.htm">
<frame name="BF" scrolling="no" noresize="" src="brand.htm">
</frameset>
</frameset>
<noframes>
<BODY bgcolor="#D1D8E8">
请使用支持帧的浏览器。
</BODY>
</noframes>
</frameset>
</html> |
|