减小字体
增大字体
作者:佚名 来源:本站整理 发布时间:2009-03-16 19:45:20
利用VB提取HTML文件中的EMAIL地址
电子邮件(EMAIL)是INTERNET上应用最广泛的一种服务之一。我们每天都在使用电子邮件,有时为了宣传我们的产品、网站等,更是离不开电子邮件,这就需要收集很多的EMAIL地址。下面我们将向大家介绍用VB自编一个EMAIL地址提取器,用来提取保存在我们硬盘中的HTML文件中所包含的EMAIL地址。 |
进入VB,选择“标准EXE”新建一工程,选择“工程”菜单下的“引用”,选中Microsoft scripting Runtime”,然后再选择“工程”菜单中的“部件”,在弹出的对话框中选择“Microsoft common dialog control 6.0”,在工具箱中加入通用对话框控件。接下来在默认窗体FORM1上添加三个标签控件,一个文本框控件text1,一个列表框控件LIST1,并命名为lstemail,三个命令command1~command3,其Caption属性分别设置为“提取”、“整理”、“保存”,设置完成的界面如下图所示: |
|
Dim X, Y, St1, St2, tmpY As Integer |
Private Sub StripEmail(FilePath As String) |
Dim tmpEmail1, tmpEmail2 As String |
Open FilePath For Input As #1 |
For X = 1 To Len(tmpEmail1) |
tmpEmail2 = Mid(tmpEmail1, X, 7) |
If tmpEmail2 = "mailto:" Then |
For Y = 1 To Len(tmpEmail1) |
tmpEmail2 = Mid(tmpEmail1, tmpY, 1) |
If tmpEmail2 = Chr(34) Or tmpEmail2 = "?" Then |
tmpEmail2 = Mid(tmpEmail1, St1 + 7, ((St2 - St1) - 7)) |
If (Left(tmpEmail2, 2) <> "//") And (Left(tmpEmail2, 1) <> " ") Then |
lstEmail.AddItem tmpEmail2 |
Private Sub Command1_Click() |
Dim fs As New FileSystemObject ' 建立 FileSystemObject |
Dim fd As Folder ' 定义 Folder 对象 |
Set fd = fs.GetFolder(Text1) |
Screen.MousePointer = vbHourglass |
FindFile fd, "*.htm" 'Text1.Text |
Screen.MousePointer = vbDefault |
Sub FindFile(fd As Folder, FileName As String) |
Dim sfd As Folder, f As File |
If UCase(f.Name) Like UCase(FileName) Then |
lblEmail = "已查找到的地址数为: " & lstEmail.ListCount |
For Each sfd In fd.SubFolders |
FindFile sfd, FileName ' 循环查找 |
Private Sub Command2_Click() |
For i = 0 To lstEmail.ListCount - 1 |
For X = 0 To lstEmail.ListCount - 1 |
If LCase(lstEmail.List(X)) = LCase(lstEmail.List(i)) Then |
lblEmail = "共有" & lstEmail.ListCount & "个地址" |
Private Sub Command3_Click() |
commondialog1.Filter = "文本文件(*.txt)*.txt" |
If commondialog1.FileName <> "" Then |
strname = commondialog1.FileName |
strname = App.Path & "emailaddress.txt" |
Open strname For Output As #1 |
For i = 0 To lstEmail.ListCount - 1 |
Print #1, lstEmail.List(i) |
本程序在WINDOWS ME、VB6.0中文企业版中运行通过。以上程序稍加修改即可实现提取其他类型文件中的EMAIL地址。 |
Tags:
作者:佚名