7,765
社区成员
发帖
与我相关
我的任务
分享
Public Sub GetLinks()
Dim L As Integer
Dim i As Integer
Dim Varl As Variant
Set Doc = Me.WebBrowser1.Document
Set All = Doc.links
L = All.length
For i = 0 To L - 1
Set Varl = All.Item(i, varempty)
Debug.Print Varl.href
Set Varl = Nothing
Next i
Set All = Nothing
Set Doc = Nothing
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate "http://WWW.hao123.COM"
End Sub
Private Sub WebBrowser1_DownloadComplete()
GetLinks
End Sub
'引用的是microsoft vbscript regular expression 5.5
Function RegExpTest(patrn, strng) 'patrn:需要查找的字符 strng:被查找的字符串
Dim regEx, Match, Matches ' 创建变量。
Set regEx = New RegExp ' 创建正则表达式。
regEx.Pattern = patrn ' 设置模式。'"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"'
regEx.IgnoreCase = True ' 设置是否区分大小写。
regEx.Global = True ' 设置全程匹配。
Set Matches = regEx.Execute(strng) ' 执行搜索。
For Each Match In Matches ' 循环遍历Matches集合。
RetStr = RetStr & Match.Value & vbCrLf
Next
RegExpTest = RetStr
End Function
Private Sub Command1_Click()
Dim URLRegExp As String, MailRegExp As String, ChiniRegExp As String
Dim FileName As String, sFile As String, MuName As String, Chans As String
Dim i As Long, arr() As String, arr1() As String, arr2() As String
URLRegExp = "http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?" 'URL正则表达式
MailRegExp = "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" '电子邮件正则表达式
ChiniRegExp = "[^\x00-\xff]* "
Open "c:\temp.html" For Binary As #1
sFile = Space(LOF(1))
Get #1, , sFile
Close #1
Text1.Text = RegExpTest(URLRegExp, sFile)
End Sub