vb怎么提取网页源代码的指定内容
1个回答
展开全部
先得到源代码:这里用WebBrowser1控件
text1=WebBrowser1.Document.documentElement.outerHTML
下面是筛选实例
自编函数Getin
范例
GetIn(字符串, 起始, 结束)
GetIn(text1, ">", "<") '截取中间
GetIn(text1, "<", "") '截取后半段
GetIn(text1, "", ">") '截取前半段
Function GetIn(ByRef Str As String, St As String, Ed As String)
If InStr(1, Str, St) <= 0 Then
If InStr(1, Str, Ed) > 0 Then
Str = Left(Str, InStr(1, Str, Ed) - 1)
Else
Str = ""
End If
GetIn = ""
Str = ""
Exit Function
End If
If InStr(1, Str, Ed) <= 0 Then
If InStr(1, Str, St) > 0 Then
Str = Right(Str, Len(Str) - InStr(1, Str, St) - Len(St) + 1)
Else
Str = ""
End If
GetIn = Str
Str = ""
Exit Function
End If
Str = Right(Str, Len(Str) - InStr(1, Str, St) - Len(St) + 1)
If Ed = "" Then
GetIn = Str
Str = ""
Exit Function
End If
GetIn = Left(Str, InStr(1, Str, Ed) - 1)
Str = Right(Str, Len(Str) - InStr(1, Str, Ed) - Len(Ed) + 1)
End Function
text1=WebBrowser1.Document.documentElement.outerHTML
下面是筛选实例
自编函数Getin
范例
GetIn(字符串, 起始, 结束)
GetIn(text1, ">", "<") '截取中间
GetIn(text1, "<", "") '截取后半段
GetIn(text1, "", ">") '截取前半段
Function GetIn(ByRef Str As String, St As String, Ed As String)
If InStr(1, Str, St) <= 0 Then
If InStr(1, Str, Ed) > 0 Then
Str = Left(Str, InStr(1, Str, Ed) - 1)
Else
Str = ""
End If
GetIn = ""
Str = ""
Exit Function
End If
If InStr(1, Str, Ed) <= 0 Then
If InStr(1, Str, St) > 0 Then
Str = Right(Str, Len(Str) - InStr(1, Str, St) - Len(St) + 1)
Else
Str = ""
End If
GetIn = Str
Str = ""
Exit Function
End If
Str = Right(Str, Len(Str) - InStr(1, Str, St) - Len(St) + 1)
If Ed = "" Then
GetIn = Str
Str = ""
Exit Function
End If
GetIn = Left(Str, InStr(1, Str, Ed) - 1)
Str = Right(Str, Len(Str) - InStr(1, Str, Ed) - Len(Ed) + 1)
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询