读书人

关于采集单页面email地址解决方案

发布时间: 2012-02-26 20:19:45 作者: rapoo

关于采集单页面email地址
http://tieba.baidu.com/f?kz=184238789

我想采集这样一个单页面的email地址 请问VB用什么代码?谢谢!

正则表达式我查到了,但是我不懂怎么用!


VB代码

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 & "|"
Next
RegExpTest = RetStr
End Function

'函数返回所有的查找的内容,以“|”号隔开,用户只需使用split将其转化为数组即可使用

URLRegExp = "http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?" 'URL正则表达式
MailRegExp = "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" '电子邮件正则表达式

[解决办法]

VB code
'引用的是microsoft   vbscript   regular   expression   5.5Function 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 = RetStrEnd FunctionPrivate Sub Command1_Click()Dim URLRegExp As String, MailRegExp As String, ChiniRegExp As StringDim FileName As String, sFile As String, MuName As String, Chans As StringDim 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 #1Text1.Text = RegExpTest(MailRegExp, sFile)End Sub 

读书人网 >VB

热点推荐