求一在一大段网页源代码中提取URL源码

2024-11-29 13:04:15
推荐回答(5个)
回答1:

呵呵,我以前写过一个函数,你试试吧:

Private Sub Command1_Click()
Text1 = FindStrMulti$(源码变量, "WWW", "COM", vbCrLf, 1)
End Sub

'取得字符串中的指定内容(字符串变量,关键字前缀,关键字后缀,输出的分隔符,是否包含关键字)
Function FindStrMulti$(Strall$, FirstStr$, EndStr$, SplitStr$, Findmod&)
Dim i&, j&
Do
i = InStr(i + 1, Strall, FirstStr)
If i = 0 Then Exit Do
If Findmod = 0 Then i = i + Len(FirstStr)
j = InStr(i, Strall, EndStr)
If j = 0 Then Exit Do
If Findmod = 1 Then j = j + Len(EndStr)
FindStrMulti = IIf(Len(FindStrMulti) > 0, FindStrMulti & SplitStr, "") & Mid(Strall, i, j - i)
Loop
End Function

回答2:

可以实现网页浏览,并查询网页中的超级链接

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
Const LB_SETHORIZONTALEXTENT = &H194

Private Sub Command1_Click()
WebBrowser1.Navigate (Text1.Text)
List1.Clear
Dim TagName, str As String
Dim count, i, k As Integer
Dim cols
List1.Clear
Set cols = WebBrowser1.Document.All
count = cols.length
k = 0
While i < count
TagName = cols.Item(i).TagName
If TagName = "A" Or TagName = "IMG" Then
str = k & " " & TagName & "... " & cols.Item(i).href
List1.AddItem (str)
SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, Me.TextWidth(str), ByVal 0&
k = k + 1
End If
i = i + 1
Wend
End Sub

回答3:

Private Sub GetLink()
Dim s As String, n As Long
Dim L As Object, c As Object
Set L = Web.Document
s = "================================" & vbCrLf
s = s & "一共有 " & L.links.Length & " 个超链接" & vbCrLf
s = s & "================================" & vbCrLf
For Each c In L.links
n = n + 1
s = s & c.innerText & " [" & c.href & "]" & vbCrLf
Next c
Text2.Text = s
End Sub

Private Sub Web_DownloadComplete()
Url.Text = Web.LocationURL
Call GetLink
End Sub

这样就可以了!

回答4:

编程实现? 当然得用正则过滤了..

回答5:

将内容逐行读出,进行判断就行了.