求大神解答如何用VB获取某个网页的<label></label>和<td></td>标签中的值,放在文本框中? 255
-----------------------------------------分割线-----------------------------------------...
-----------------------------------------分割线---------------------------------------------
<tbody>
<tr>
<td trans="traffic_current_connection">当前连接</td>
<td data-bind="text: currentConnectedTime">00:37:00</td>
<td data-bind="text: currentReceived">38.43MB</td>
<td data-bind="text: currentSent">3.26MB</td>
<td data-bind="text: currentTraffic">41.69MB</td>
</tr>
<tr>
<td trans="traffic_current_month_data">当月</td>
<td data-bind="text: monthlyConnectedTime">65:51:42</td>
<td data-bind="text: monthlyReceived">15.7GB</td>
<td data-bind="text: monthlySent">0.58GB</td>
<td data-bind="text: monthlyTraffic">16.29GB</td>
</tr>
</tbody>
获取<td data-bind="text: monthlyTraffic">16.29GB</td>这个标签中的流量数据,数据是实时变动的。
-----------------------------------------分割线---------------------------------------------
<div class="row-fluid">
<label trans="current_flux" class="span7 side-right">当前流量</label>
<label class="span5" id="tdCurrentFlux" data-bind="text: current_Flux">41.86MB</label>
</div>
<!-- div class="row-fluid">
<label trans="total_flux" class="span7 side-right"></label>
<label class="span5" id="tdTotalFlux" data-bind='text: total_Flux'></label>
</div -->
<div class="row-fluid">
<label trans="connected_time" class="span7 side-right">持续时间</label>
<label class="span5" id="tdConnectedTime" data-bind="text: connected_Time">00:40:24</label>
</div>
<div class="row-fluid">
<label trans="flux_up" class="span7 side-right">上传速率</label>
<label class="span5" id="tdUpSpeed" data-bind="text: up_Speed">1.66Kb/s</label>
</div>
<div class="row-fluid">
<label trans="flux_down" class="span7 side-right">下载速率</label>
<label class="span5" id="tdDownSpeed" data-bind="text: down_Speed">3.25Kb/s</label>
</div>
获取<label class="span5" id="tdDownSpeed" data-bind="text: down_Speed">3.25Kb/s</label>这里面的值,值是变动的。
-----------------------------------------分割线--------------------------------------------- 展开
<tbody>
<tr>
<td trans="traffic_current_connection">当前连接</td>
<td data-bind="text: currentConnectedTime">00:37:00</td>
<td data-bind="text: currentReceived">38.43MB</td>
<td data-bind="text: currentSent">3.26MB</td>
<td data-bind="text: currentTraffic">41.69MB</td>
</tr>
<tr>
<td trans="traffic_current_month_data">当月</td>
<td data-bind="text: monthlyConnectedTime">65:51:42</td>
<td data-bind="text: monthlyReceived">15.7GB</td>
<td data-bind="text: monthlySent">0.58GB</td>
<td data-bind="text: monthlyTraffic">16.29GB</td>
</tr>
</tbody>
获取<td data-bind="text: monthlyTraffic">16.29GB</td>这个标签中的流量数据,数据是实时变动的。
-----------------------------------------分割线---------------------------------------------
<div class="row-fluid">
<label trans="current_flux" class="span7 side-right">当前流量</label>
<label class="span5" id="tdCurrentFlux" data-bind="text: current_Flux">41.86MB</label>
</div>
<!-- div class="row-fluid">
<label trans="total_flux" class="span7 side-right"></label>
<label class="span5" id="tdTotalFlux" data-bind='text: total_Flux'></label>
</div -->
<div class="row-fluid">
<label trans="connected_time" class="span7 side-right">持续时间</label>
<label class="span5" id="tdConnectedTime" data-bind="text: connected_Time">00:40:24</label>
</div>
<div class="row-fluid">
<label trans="flux_up" class="span7 side-right">上传速率</label>
<label class="span5" id="tdUpSpeed" data-bind="text: up_Speed">1.66Kb/s</label>
</div>
<div class="row-fluid">
<label trans="flux_down" class="span7 side-right">下载速率</label>
<label class="span5" id="tdDownSpeed" data-bind="text: down_Speed">3.25Kb/s</label>
</div>
获取<label class="span5" id="tdDownSpeed" data-bind="text: down_Speed">3.25Kb/s</label>这里面的值,值是变动的。
-----------------------------------------分割线--------------------------------------------- 展开
1个回答
展开全部
用正则匹配即可
Option Explicit
Function GetSource$(Source$) '//正则匹配<td></td>
Dim reg As Object
Dim matchs As Object, match As Object
Dim s As String, i As Integer
Set reg = CreateObject("vbscript.regExp")
reg.Global = True
reg.IgnoreCase = True
reg.MultiLine = True
reg.Pattern = "<label.*?>(.*?)<\/label>"
Set matchs = reg.Execute(Source)
For Each match In matchs
i = i + 1
s = s & match.SubMatches(0) + vbCrLf
Next
GetSource = s
End Function
Function div$(Source$) '//正则匹配 <div></div>
Dim reg As Object
Dim matchs As Object, match As Object
Dim s As String, i As Integer
Set reg = CreateObject("vbscript.regExp")
reg.Global = True
reg.IgnoreCase = True
reg.MultiLine = True
reg.Pattern = "<div.*?>(.*?)<\/div>"
Set matchs = reg.Execute(Source)
For Each match In matchs
i = i + 1
s = s & match.SubMatches(0) + vbCrLf
Next
div = s
End Function
Private Sub Command1_Click()
MsgBox "div标签获取" + vbCrLf + GetSource$(Text1)
MsgBox "label标签获取" + vbCrLf + GetSource$(Text1)
End Sub
追问
不是很会正则,可否亮下代码,还有这个是路由器的管理界面,是吧它当文档打开然后用正则匹配字符是吧
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询