VB提取网页指定内容
比如网页源代码如下:***************<em>3</em><sup>#</sup>***************<em>4</em><sup>#</sup>*...
比如网页源代码如下:
***************
<em>3</em><sup>#</sup>
***************
<em>4</em><sup>#</sup>
***************
<em>5</em><sup>#</sup>
***代表可以忽略的内容,现在我要求能把<em>5</em>其中的数值提取出来,如:5
全部提取比如:3、4、5,或者提取最大值如:5
楼下的答案不对,。继续请求答案。。。。。。 展开
***************
<em>3</em><sup>#</sup>
***************
<em>4</em><sup>#</sup>
***************
<em>5</em><sup>#</sup>
***代表可以忽略的内容,现在我要求能把<em>5</em>其中的数值提取出来,如:5
全部提取比如:3、4、5,或者提取最大值如:5
楼下的答案不对,。继续请求答案。。。。。。 展开
4个回答
2011-05-01
展开全部
Private Declare Function icePub_getSubString Lib "icePubDll.dll" (ByVal strText As String,ByVal strResult As String,ByVal strBegin As String,ByVal strEnd As String,ByVal startIndex As Integer) As Integer
Dim a2 As Integer
Dim strText As String
Dim strSubText As String
'strText 等于html页代码
a2=0
While a2 >= 0
strSubText=Space(1024+1)
a2=icePub_getSubString(strText,strSubText,"<em>","</em>",a2)
MsgBox strSubText
Wend
http://dl.icese.net/dev.php?f=icePubDll.rar 下载
Dim a2 As Integer
Dim strText As String
Dim strSubText As String
'strText 等于html页代码
a2=0
While a2 >= 0
strSubText=Space(1024+1)
a2=icePub_getSubString(strText,strSubText,"<em>","</em>",a2)
MsgBox strSubText
Wend
http://dl.icese.net/dev.php?f=icePubDll.rar 下载
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim data As Integer, strText As String
Dim MaxData As Integer, i As Integer, j As Integer
strText = "***************<em>3</em><sup>#</sup>***************<em>4</em><sup>#</sup>***************<em>5</em><sup>#</sup>"
i = 1
j = 1
MaxData = 0
Do While i <> 0 And j <> 0
i = InStr(j, strText, "<em>")
If i <> 0 Then
j = InStr(i, strText, "</em>")
data = Mid(strText, i + 4, j - i - 4)
Debug.Print data
If data > MaxData Then MaxData = data
End If
Loop
Debug.Print "最大值:" & MaxData
Dim MaxData As Integer, i As Integer, j As Integer
strText = "***************<em>3</em><sup>#</sup>***************<em>4</em><sup>#</sup>***************<em>5</em><sup>#</sup>"
i = 1
j = 1
MaxData = 0
Do While i <> 0 And j <> 0
i = InStr(j, strText, "<em>")
If i <> 0 Then
j = InStr(i, strText, "</em>")
data = Mid(strText, i + 4, j - i - 4)
Debug.Print data
If data > MaxData Then MaxData = data
End If
Loop
Debug.Print "最大值:" & MaxData
更多追问追答
追问
data = Mid(strText, i + 4, j - i - 4) '出错,提示类型不匹配
再一个问题补充的是
我给的是标记,有些中间不是数字 有些为空。。
追答
只要提取数字吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
使用正则表达式:
VB工程→引用 Microsoft VBScript Regular Expressions 5.5
Private Sub Command1_Click()
Dim a As New RegExp
Dim strP As String
Dim strT As String
Dim b As MatchCollection
Dim c As Match
Dim d As Long
Dim strS As String
strT = "<em>3</em><sup>#</sup>"
strT = strT & "***************"
strT = strT & "<em>4</em><sup>#</sup>"
strT = strT & "***************"
strT = strT & "<em>5</em><sup>#</sup>"
strP = "<em>(\d)</em>"
a.Pattern = strP
a.MultiLine = True
a.IgnoreCase = True
a.Global = True
Set b = a.Execute(strT)
For Each c In b
strS = strS & c.SubMatches(0) & " "
If Val(c.SubMatches(0)) > d Then d = Val(c.SubMatches(0))
Next
MsgBox "提取数据:" & strS & vbCrLf & "最大值:" & d
End Sub
VB工程→引用 Microsoft VBScript Regular Expressions 5.5
Private Sub Command1_Click()
Dim a As New RegExp
Dim strP As String
Dim strT As String
Dim b As MatchCollection
Dim c As Match
Dim d As Long
Dim strS As String
strT = "<em>3</em><sup>#</sup>"
strT = strT & "***************"
strT = strT & "<em>4</em><sup>#</sup>"
strT = strT & "***************"
strT = strT & "<em>5</em><sup>#</sup>"
strP = "<em>(\d)</em>"
a.Pattern = strP
a.MultiLine = True
a.IgnoreCase = True
a.Global = True
Set b = a.Execute(strT)
For Each c In b
strS = strS & c.SubMatches(0) & " "
If Val(c.SubMatches(0)) > d Then d = Val(c.SubMatches(0))
Next
MsgBox "提取数据:" & strS & vbCrLf & "最大值:" & d
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
来个最简单的,网页源码放在text1
Private Sub Command1_Click()
t = Split(Text1, "<em>")
For i = 1 To UBound(t)
j = Split(t(i), "</em>")
Print j(0)
Next
End Sub
Private Sub Command1_Click()
t = Split(Text1, "<em>")
For i = 1 To UBound(t)
j = Split(t(i), "</em>")
Print j(0)
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询