Private Sub Command1_Click() a = "<form name=""dfd"" post=""\h.htnl""><table><td> 123 </td></table></form>" b = InStr(a, "<td>") c = InStr(a, "</td>") MsgBox Replace(Replace(Mid(a, b), "<td>", ""), Mid(a, c), "")End Sub 简单地写了一下,根据你的要求,但是还有很多别的方法的。
Public Function FindStrMulti$(Strall$, FirstStr$, EndStr$, SplitStr$) '提取字符串或网页源代码中所有指定代码 '参数 '总文本,起始字符串,终止字符串,分隔符 Dim i&, j& j = 1 Do i = InStr(j, Strall, FirstStr) If i = 0 Then Exit Do End If i = i + Len(FirstStr) j = InStr(i, Strall, EndStr) If j > 0 Then FindStrMulti = IIf(Len(FindStrMulti) > 0, FindStrMulti & SplitStr, "") & Mid(Strall, i, j - i) Else Exit Do End If Loop End Function 这个函数可以截取指定字符串之间的内容哦msgbox FindStrMulti(str1, "<td>", "</td>", "")
如<form name="dfd" post="\h.htnl">
<table>
<td> 123 </td>
</table>
</form>
如何抓取数据“123”呢,tabel 什么标示都没有,ID,Name都没有?请教各位大侠了,先谢过。
还可以遍历DOM的td元素.如果html符合xml规范,还可以用xml Dom查询到.
直接分析字符串,或用正则也能搞定吧,方法多多
a = "<form name=""dfd"" post=""\h.htnl""><table><td> 123 </td></table></form>"
b = InStr(a, "<td>")
c = InStr(a, "</td>")
MsgBox Replace(Replace(Mid(a, b), "<td>", ""), Mid(a, c), "")End Sub
简单地写了一下,根据你的要求,但是还有很多别的方法的。
'参数
'总文本,起始字符串,终止字符串,分隔符
Dim i&, j&
j = 1
Do
i = InStr(j, Strall, FirstStr)
If i = 0 Then
Exit Do
End If
i = i + Len(FirstStr)
j = InStr(i, Strall, EndStr)
If j > 0 Then
FindStrMulti = IIf(Len(FindStrMulti) > 0, FindStrMulti & SplitStr, "") & Mid(Strall, i, j - i)
Else
Exit Do
End If
Loop
End Function
这个函数可以截取指定字符串之间的内容哦msgbox FindStrMulti(str1, "<td>", "</td>", "")
'cells代表列
'自己修改一下012这些数据即可.
1.直接dhtml方式访问获取,参考11楼。
2.用document.body.innerhtml得到页面源代码,然后用vb字符串处理函数分析取得,或者用正则。另外如果不用webbrowser的话可以用xmlhttp下载得到页面源代码,然后处理方法同上面的2。