我使用VBA填写网络表单,如下所示:
Option Explicit
Sub Command()
Dim IE As Object
Dim tbls, tbl, trs, tr, tds, td, chkBox, check
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "http://www.wvgs.wvnet.edu/oginfo/pipeline/pipeline2.asp"
Do
DoEvents
Loop Until IE.ReadyState = 4
Set chkBox = IE.Document.getElementsByTagName("input")
' Select Check Boxes
For Each check In chkBox
'If check.Name = "allbox" Then
If check.Name = "paychecktable" Then
check.Click
End If
'Enter the Permit Number
If check.Name = "prmtenter" Then
check.Value = "05588"
End If
Next
With IE
' Enter the counter number into the drop down menu
.Document.forms("form1").Item("cntyenter").Value = "33"
.Document.forms("form1").Item("submit").Click
Do
DoEvents
Loop Until IE.ReadyState = 4
End With
'Dim tbody, p, i As Long, body
'
'Set p = IE.Document.getElementsByTagName("body")(200)
'
'MsgBox p.innerText
'Set tbl = p.getElementsByTagName("table")
'Set tbody = tbl.getElementsByTagName("tbody")(0)
'Set tr = tbody.getElementsByTagName("tr")
'
'MsgBox tr.Length
End Sub
哪个运行正常。 现在的问题是我需要访问在水平中断下面生成的HTML表,但是VBA只识别三个HTML表,这些表对应于水平中断之上的HTML。IE
<html>
<head><title>WVGES O&G Record Reporting System</title>
<LINK REL="stylesheet" HREF="text3.css">
<STYLE TYPE="text/css">
<!--
TABLE.main {border: 0px solid #000000; background-color: transparent; padding-left: 2px; padding-right: 5px; padding-top: 0px; padding-bottom: 0px;}
-->
</STYLE>
<SCRIPT language="JavaScript">
<!--
function zoomToSite() {
county = form1.cntyenter.value*100000;
permit = form1.prmtenter.value*1;
state = 4700000000*1;
apinum = (state + county + permit)*1;
var strURL = "http://ims.wvgs.wvnet.edu/wvog1/viewer.htm?ActiveLayer=11&Query=API%3D"+apinum+"&QueryZoom=Yes&Layers=011111100001000"
window.open(strURL,"whatever","");
}
//-->
</SCRIPT>
<script language="JavaScript">
<!--
function variable_in_link(varible_value)
{
new_win = window.open(href='http://ims.wvgs.wvnet.edu/wvog/viewer.htm?ActiveLayer=12&Query=API%3D'+varible_value+'&QueryZoom=Yes&Layers=0000111100001000')
}
// -->
</script>
<SCRIPT language="JavaScript">
<!-- hide script from old browsers
function validate(form1) {
var wHeight,wWidth,sHeight,sWidth,bitDepth;
sHeight = screen.height;
sWidth = screen.width;
bitDepth = screen.colorDepth;
browserversion="0";
if (navigator.appVersion.indexOf("2.") != -1) {browserversion="2"};
if (navigator.appVersion.indexOf("3.") != -1) {browserversion="3"};
if (navigator.appVersion.indexOf("5.") != -1) {browserversion="5"};
if ((navigator.appVersion.indexOf("4.7") != -1) && (navigator.appName == 'Netscape')) {browserversion="4"};
if ((navigator.appVersion.indexOf("4.8") != -1) && (navigator.appName == 'Netscape')) {browserversion="4"};
if ((navigator.appVersion.indexOf("4.9") != -1) && (navigator.appName == 'Netscape')) {browserversion="4"};
if (navigator.appVersion.indexOf("6.") != -1) {browserversion="6"};
if (navigator.appName == 'Netscape' && browserversion < 5) {
wHeight = window.clientHeight;
wWidth = window.clientWidth;
}
else {
wHeight = document.body.clientHeight;
wWidth = document.body.clientWidth;
}
document.cookie = "wHeight=" + wHeight + ";";
document.cookie = "wWidth=" + wWidth + ";";
document.cookie = "sHeight=" + sHeight + ";";
document.cookie = "sWidth=" + sWidth + ";";
document.cookie = "bitDepth=" + bitDepth + ";";
form1.jscheck.value="data";
permit=form1.prmtenter.value;
loc=form1.locchecktable.checked;
own=form1.ownchecktable.checked;
pay=form1.paychecktable.checked;
prd=form1.prdchecktable.checked;
str=form1.strchecktable.checked;
mlc=form1.mlcchecktable.checked;
plg=form1.plgchecktable.checked;
wsc=form1.wscchecktable.checked;
bhloc=form1.bhlocchecktable.checked;
if ((loc == false) && (own == false) && (pay == false) && (prd == false) && (str == false) && (mlc == false) && (plg == false) && (bhloc == false) && (wsc == false)) {
alert('You must select at least one datatype');
return false;
}
if (permit > 0 && permit < 100000) {
}
else {
alert('You must enter a Number Value for Permit # between 1 and 99999');
return false;
}
}
//-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!-- document.form1.allbox.onclick = un_check; //-->
function un_check(){
for (var i = 0; i < document.form1.elements.length; i++) {
var e = document.form1.elements[i];
if ((e.name != 'allbox') && (e.type == 'checkbox')) {
e.checked = document.form1.allbox.checked;
}
}
}
</SCRIPT>
</head>
<BODY class=stuff marginheight="0" topmargin="0" vspace="0" marginwidth="0" leftmargin="0" hspace="0" style="margin:1; padding:1">
<table class=dog cellpadding=0 cellspacing=0><tr><TD align=left valign=top>
<img src="http://www.wvgs.wvnet.edu/www/general/logorrr2.gif" width="128" height="66" align="left" alt="WVGES">
<br clear=left>
<center><font size=3><b>"Pipeline"<b></font><center></td>
<td width=5> </td>
<td>
<form name="form1" onSubmit="return validate(this);" method=post action="pipeline2.asp">
<input type=hidden name=jscheck value="">
<table width=475 class=cat valign=top>
<tr height=15><td width=150 valign=top ><nobr>Select County:
<select name="cntyenter" size=1> </nobr>
<Option value="1" >(001) Barbour
<Option value="3" >(003) Berkeley
<Option value="5" >(005) Boone
<Option value="7" >(007) Braxton
<Option value="9" >(009) Brooke
<Option value="11" >(011) Cabell
<Option value="13" >(013) Calhoun
<Option value="15" >(015) Clay
<Option value="17" >(017) Doddridge
<Option value="19" >(019) Fayette
<Option value="21" >(021) Gilmer
<Option value="23" >(023) Grant
<Option value="25" >(025) Greenbrier
<Option value="27" >(027) Hampshire
<Option value="29" >(029) Hancock
<Option value="31" >(031) Hardy
<Option value="33" selected >(033) Harrison
<Option value="35" >(035) Jackson
<Option value="37" >(037) Jefferson
<Option value="39" >(039) Kanawha
<Option value="41" >(041) Lewis
<Option value="43" >(043) Lincoln
<Option value="45" >(045) Logan
<Option value="47" >(047) McDowell
<Option value="49" >(049) Marion
<Option value="51" >(051) Marshall
<Option value="53" >(053) Mason
<Option value="55" >(055) Mercer
<Option value="57" >(057) Mineral
<Option value="59" >(059) Mingo
<Option value="61" >(061) Monongalia
<Option value="63" >(063) Monroe
<Option value="65" >(065) Morgan
<Option value="67" >(067) Nicholas
<Option value="69" >(069) Ohio
<Option value="71" >(071) Pendleton
<Option value="73" >(073) Pleasants
<Option value="75" >(075) Pocahontas
<Option value="77" >(077) Preston
<Option value="79" >(079) Putnam
<Option value="81" >(081) Raleigh
<Option value="83" >(083) Randolph
<Option value="85" >(085) Ritchie
<Option value="87" >(087) Roane
<Option value="89" >(089) Summers
<Option value="91" >(091) Taylor
<Option value="93" >(093) Tucker
<Option value="95" >(095) Tyler
<Option value="97" >(097) Upshur
<Option value="99" >(099) Wayne
<Option value="101" >(101) Webster
<Option value="103" >(103) Wetzel
<Option value="105" >(105) Wirt
<Option value="107" >(107) Wood
<Option value="109" >(109) Wyoming
</select></td>
<td width = 275 colspan=3><b>Select datatypes:</b> <input type=checkbox name=allbox value="bill" onclick=un_check()><b>(Check All)</b></td></tR>
<tr height=15><td >Enter Permit #: <input type=text name="prmtenter" size=10 value="05588"</td></td>
<td rowspan=2>
<nobr><input type=checkbox name="locchecktable" value="yes" >Location</nobr><br />
<nobr><input type=checkbox name="ownchecktable" value="yes" >Owner/Completion</nobr><br />
<nobr><input type=checkbox name="paychecktable" value="yes" checked >Pay/Show/Water</nobr><br /></td>
<td rowspan=2>
<nobr><input type=checkbox name="prdchecktable" value="yes" >Production</nobr><br />
<nobr><input type=checkbox name="strchecktable" value="yes" >Stratigraphy</nobr><br />
<nobr><input type=checkbox name="mlcchecktable" value="yes" >Logs</nobr><br /></td>
<td rowspan=2>
<nobr><input type=checkbox name="plgchecktable" value="yes" >Plugging</nobr><br />
<nobr><input type=checkbox name="wscchecktable" value="yes" >Sample</nobr><br />
<nobr><input type=checkbox name="bhlocchecktable" value="yes" >Btm Hole Loc</nobr><br />
</td></tr>
<tr height=25><td><input type="submit" name=submit value="Get Data">
<INPUT TYPE="RESET" Value="Reset" > </td>
</td>
</tr></table>
<td width=5> </td>
<td width=50 valign=center>
<a href="http://www.wvgs.wvnet.edu/oginfo/pipeline/tabledesc/ogdesc.html"><nobr>Table Descriptions</nobr></a><br>
<a href="http://www.wvgs.wvnet.edu/oginfo/pipeline/cntycode.html"><nobr>County Code Translations</nobr></a><br>
<a href="http://www.wvgs.wvnet.edu/oginfo/pipeline/series.html"><nobr>Permit-Numbering Series</nobr></a><br>
<a href="http://www.wvgs.wvnet.edu/oginfo/pipeline/usage_notes.html"><nobr>Usage Notes</nobr></a><br>
<a href="http://www.wvgs.wvnet.edu/oginfo/pipeline/contact.html"><nobr>Contact Information</nobr></a><br>
<a href="http://www.wvgs.wvnet.edu/oginfo/pipeline/pipeline2.asp">Disclaimer</a> <br>
<a href="http://www.wvgs.wvnet.edu/www/index.html"><nobr>WVGES Main</nobr></a><br>
<nobr><a href="http://www.wvgs.wvnet.edu/pipe2/OGWISHelp.aspx">"Pipeline-Plus"</a><font color=red> New</font></nobr><br>
</td></tr></table>
<hr>
<!-- <table style="border: 0px solid #FFFFFF; background-color: transparent;" width=99%><tr><td width=50%> West Virginia Geological & Economic Survey </td>
<td width=30% align=right>
Report Time: Monday, September 14, 2015 2:56:49 PM</td></tr></table>
//-->
<table class=dog width=99%><tr><td width=40%> WV Geological & Economic Survey: </td><td width =30%> <font size=3><B>Well: County = 33 Permit = 05588</b></font><td width=30% align=right> Report Time: Monday, September 14, 2015 2:56:49 PM</td></tr></table><p>Pay/Show/Water Information: <BR><table cellpadding=0 cellspacing=0><TR><TD><B>API</b></td><TD><B>CMP_DT</b></td><TD><B>ACTIVITY</b></td><TD><B>PRODUCT</b></td><TD><B>SECTION</b></td><TD><B>DEPTH_TOP</b></td><TD><B>FM_TOP</b></td><TD><B>DEPTH_BOT</b></td><TD><B>FM_BOT</b></td><TD><B>G_BEF</b></td><TD><B>G_AFT</b></td><TD><B>O_BEF</b></td><TD><B>O_AFT</b></td><TD><B>WATER_QNTY</b></td></tr><tr><td align=right><nobr>4703305588</nobr></td><td align=right><nobr>8/30/2012</nobr></td><td align=left><nobr>Water</nobr></td><td align=left><nobr>Fresh Water</nobr></td><td align=left><nobr>Vertical</nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=right><nobr>20</nobr></td><td align=left><nobr>Pennsylvanian System</nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td></tr><tr><td align=right><nobr>4703305588</nobr></td><td align=right><nobr>8/30/2012</nobr></td><td align=left><nobr>Water</nobr></td><td align=left><nobr>Fresh Water</nobr></td><td align=left><nobr>Vertical</nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=right><nobr>23</nobr></td><td align=left><nobr>Pennsylvanian System</nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td></tr><tr><td align=right><nobr>4703305588</nobr></td><td align=right><nobr>8/30/2012</nobr></td><td align=left><nobr>Water</nobr></td><td align=left><nobr>Fresh Water</nobr></td><td align=left><nobr>Vertical</nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=right><nobr>40</nobr></td><td align=left><nobr>Pennsylvanian System</nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td></tr><tr><td align=right><nobr>4703305588</nobr></td><td align=right><nobr>8/30/2012</nobr></td><td align=left><nobr>Water</nobr></td><td align=left><nobr>Fresh Water</nobr></td><td align=left><nobr>Vertical</nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=right><nobr>45</nobr></td><td align=left><nobr>Pennsylvanian System</nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td></tr><tr><td align=right><nobr>4703305588</nobr></td><td align=right><nobr>8/30/2012</nobr></td><td align=left><nobr>Water</nobr></td><td align=left><nobr>Fresh Water</nobr></td><td align=left><nobr>Vertical</nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=right><nobr>50</nobr></td><td align=left><nobr>Pennsylvanian System</nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td></tr><tr><td align=right><nobr>4703305588</nobr></td><td align=right><nobr>8/30/2012</nobr></td><td align=left><nobr>Water</nobr></td><td align=left><nobr>Salt Water</nobr></td><td align=left><nobr>Vertical</nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=right><nobr>1510</nobr></td><td align=left><nobr>Mississippian</nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td></tr><tr><td align=right><nobr>4703305588</nobr></td><td align=right><nobr>8/30/2012</nobr></td><td align=left><nobr>Pay</nobr></td><td align=left><nobr>Gas</nobr></td><td align=left><nobr>Deviated</nobr></td><td align=right><nobr>8127</nobr></td><td align=left><nobr>Marcellus Sh</nobr></td><td align=right><nobr>14874</nobr></td><td align=left><nobr>Marcellus Sh</nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td><td align=left><nobr></nobr></td></tr></table><p>
</form>
</body>
</html>
水平休息后的最终表
答案 0 :(得分:1)
以下内容会一直等到.Document
中至少有4个表才会继续。
Dim dTill As Double
With IE
' Enter the counter number into the drop down menu
.Document.forms("form1").Item("cntyenter").Value = "33"
.Document.forms("form1").Item("submit").Click
Do While IE.busy Or IE.ReadyState <> 4
DoEvents
Loop
dTill = Timer + 5 'maximum of 5 seconds to keep looking
Do While dTill > Timer And .Document.getElementsByTagName("table").Length < 4
Debug.Print .Document.getElementsByTagName("table").Length
DoEvents
Loop
Debug.Print .Document.getElementsByTagName("table").Length
Debug.Print .Document.getElementsByTagName("table")(2).getElementsByTagName("tr")(0).getElementsByTagName("td")(0).innertext
Debug.Print .Document.getElementsByTagName("table")(3).getElementsByTagName("tr")(0).getElementsByTagName("td")(0).innertext
End With
最多等待5秒钟,以便你不会永远等待一些不会出现的事情。 .Length
(或数量)属性是基于1的(例如,1,2,3等),而集合中元素的索引位置是基于0(例如,0,1,2等)。报告报告日期时间的表格将被丢弃,但这不应该是重要的,因为它只是在东部时间(UTC-05)回吐当前的现在。
包含API CMP_DT ACTIVITY PRODUCT, etc
数据的表位于索引位置3.您可以遍历第一个<td>
中<tr>
的列标签和每隔一行对于数据。
答案 1 :(得分:0)