VB获取网页源码中的内容
以下为路由器网页源码中的一段代码.
我想要获取其中的
Firmwave Version =v1.00.25
MAC Address =00:21:29:EF:0D:99
Router Name =WRTU54G-TM
获取的值分别显示在text1.text,text2.text,text3.text中。请问各位朋友用WebBrowser控件怎么实现呢。其它控件也行。谢谢各位朋友了.
Router Information </B></P></FONT></TD>
<TD width=8 bgColor=#000000 height=25> </TD>
<TD width=101 height=25>
<SCRIPT>ShowText(share.firmwarever)</SCRIPT>
Firmware Version : </TD>
<TD><B>v1.00.25, May. 25, 2010</B></TD>
<TD width=13 height=25> </TD>
<TD width=15 background=UI_05.gif height=25> </TD></TR>
<TD colSpan=3 height=25> </TD>
<TD width=101 height=25>
<SCRIPT>ShowText(stacontent.curtime)</SCRIPT>
Current Time : </TD>
<TD><B>Not Available </B></TD>
<TD width=13 height=25> </TD>
<TD width=15 background=UI_05.gif height=25> </TD></TR>
<TR>
<TD width=156 bgColor=#e7e7e7 height=25> </TD>
<TD colSpan=3 height=25> </TD>
<TD width=101 height=25>
<SCRIPT>ShowText(share.macaddr)</SCRIPT>
MAC Address : </TD>
<TD><B>00:21:29:EF:0D:99</B></TD>
<TD width=13 height=25> </TD>
<TD width=15 background=UI_05.gif height=25> </TD></TR>
<TR>
<TD width=156 bgColor=#e7e7e7 height=25> </TD>
<TD width=8 background=UI_04.gif height=25> </TD>
<TD colSpan=3 height=25> </TD>
<TD width=101 height=25>
<SCRIPT>ShowText(share.routename)</SCRIPT>
Router Name : </TD>
<TD><B>WRTU54G-TM</B></TD>
<TD width=101 height=25>
<SCRIPT>ShowText(share.hostname)</SCRIPT>
IP Address : </FONT></TD>
<TD><FONT style="FONT-SIZE: 8pt"><B>0.0.0.0</B></FONT></TD>
<TD width=13 height=25> </TD>
<TD width=15 background=UI_05.gif height=25> </TD></TR>
<TR>
<TD width=156 bgColor=#e7e7e7 height=25> </TD>
<TD width=8 height=25><IMG height=30 src="UI_04.gif" width=8 border=0></TD>
<TD bgColor=#ffffff colSpan=3 height=25> </TD>
<TD width=101 bgColor=#ffffff height=25><FONT style="FONT-SIZE: 8pt">
<SCRIPT>ShowText(share.submask)</SCRIPT>
Subnet Mask : </FONT></TD>
<TD width=296 bgColor=#ffffff height=25><FONT style="FONT-SIZE: 8pt"><B>0.0.0.0</B></FONT></TD>
<TD width=13 bgColor=#ffffff height=25> </TD>
<TD width=15 bgColor=#ffffff height=25><IMG height=30 src="UI_05.gif" width=15 border=0></TD></TR>
<TR>
<TD width=101 bgColor=#ffffff height=25><FONT style="FONT-SIZE: 8pt">
<SCRIPT>ShowText(share.defgateway)</SCRIPT>
Default Gateway : </FONT></TD>
<TD width=296 bgColor=#ffffff height=25><FONT style="FONT-SIZE: 8pt"><B>0.0.0.0</B></FONT></TD>
<TD width=13 bgColor=#ffffff height=25> </TD>
<TD width=15 bgColor=#ffffff height=25><IMG height=30 src="UI_05.gif" width=15 border=0></TD></TR>
<TR>
<TD width=156 bgColor=#e7e7e7 height=25> </TD>
<TD><FONT style="FONT-SIZE: 8pt">
<SCRIPT>ShowText(share.dns)</SCRIPT>
DNS 1 : </FONT></TD>
<TD><FONT style="FONT-SIZE: 8pt"><B></B></FONT></TD>
<TD width=13 height=25> </TD>
<TD width=15 background=UI_05.gif height=25> </TD></TR>
<TR>
<TD width=156 bgColor=#e7e7e7 height=25> </TD>
<SCRIPT>ShowText(share.dns)</SCRIPT>
</TD>
<TD width=13 height=25> </TD>
<TD width=15 background=UI_05.gif height=25> </TD></TR>
<TD width=15 background=UI_05.gif> </TD></TR></TBODY></TABLE></TD>
<TD vAlign=top width=176 bgColor=#6666cc>
<TABLE cellSpacing=0 cellPadding=0 width=176 border=0>
<TBODY>
<TR>
<TD width=11 bgColor=#6666cc height=25> </TD>
<TD width=156 bgColor=#6666cc height=25><FONT color=#ffffff><SPAN><BR>
<SCRIPT>ShowText(hstatrouter2.right1)</SCRIPT>
<B>Firmware Version. </B>This is the Router's current firmware. <BR><BR>
<SCRIPT>ShowText(hstatrouter2.right2)</SCRIPT>
<B>Current Time. </B>This shows the time, as you set on the Setup Tab. <BR><BR>
<SCRIPT>ShowText(hstatrouter2.right3)</SCRIPT>
<B>MAC Address. </B>This is the Router's MAC Address, as seen by your ISP. <BR><BR>
<SCRIPT>ShowText(hstatrouter2.right4)</SCRIPT>
<B>Router Name. </B>This is the specific name for the Router, which you set on the Setup Tab. <BR><B><A href="help/Status-Help.htm" target=_blank>
<SCRIPT>ShowText(share.more)</SCRIPT>
<SCRIPT>document.write("<INPUT onclick=window.location.replace('Router-Status.htm') type=button name=refresh_button value="" + sbutton.refresh + "">");</SCRIPT>
<INPUT onclick="window.location.replace('Router-Status.htm')" type=button value=Refresh name=refresh_button> </TD>
<TD width=15 bgColor=#000000 height=33> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></FORM></DIV></BODY></HTML>
[解决办法]
Private Sub TestReg()
Dim strData As String
Dim reg As Object
Dim matchs As Object, match As Object
strData = "<SCRIPT>ShowText(share.firmwarever)</SCRIPT>" & vbCrLf & _
"Firmware Version : </TD>" & vbCrLf & _
"<TD><B>v1.00.25, May. 25, 2010</B></TD>" & vbCrLf & _
"<TD width=13 height=25> </TD><TD width=101 height=25>" & vbCrLf & _
"<SCRIPT>ShowText(share.macaddr)</SCRIPT>" & vbCrLf & _
"MAC Address : </TD>" & vbCrLf & _
"<TD><B>00:21:29:EF:0D:99</B></TD>" & vbCrLf & _
"<TD width=13 height=25> </TD>" & vbCrLf & _
"<TD width=15 background=UI_05.gif height=25> </TD></TR>" & vbCrLf & _
"<TR>" & vbCrLf & _
"<TD width=156 bgColor=#e7e7e7 height=25> </TD>" & vbCrLf & _
"<TD width=8 background=UI_04.gif height=25> </TD>" & vbCrLf & _
"<TD colSpan=3 height=25> </TD>" & vbCrLf & _
"<TD width=101 height=25>" & vbCrLf & _
"<SCRIPT>ShowText(share.routename)</SCRIPT>" & vbCrLf & _
"Router Name : </TD>" & vbCrLf & _
"<TD><B>WRTU54G-TM</B></TD>" & vbCrLf & _
"<TD width=101 height=25>" & vbCrLf & _
"<SCRIPT>ShowText(share.hostname)</SCRIPT>"
Set reg = CreateObject("vbscript.regExp")
reg.Global = True
reg.IgnoreCase = True
reg.MultiLine = True
reg.Pattern = "v[\d\.]+"
Set matchs = reg.Execute(strData)
Debug.Print matchs(0).Value
reg.Pattern = "[\dA-Z]{2}:[\dA-Z]{2}:[\dA-Z]{2}:[\dA-Z]{2}:[\dA-Z]{2}:[\dA-Z]{2}"
Set matchs = reg.Execute(strData)
Debug.Print matchs(0).Value
reg.Pattern = "Router Name[^>]*?</TD>\r\n<TD><B>(.*?)</B>"
Set matchs = reg.Execute(strData)
Debug.Print matchs(0).SubMatches(0)
End Sub