您的位置:程序门 -> vb -> 基础类



webbrowser保存一个网页中的超连接


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


webbrowser保存一个网页中的超连接[已结贴,结贴人:keboy4]
发表于:2007-08-24 19:23:26 楼主
--------如何在webbrowser找到一个网页中的超连接,并保存。已经有如下代码

'添加一个webbrowser1到form1中,再添加一个command1到form1中,添加一个list1到form1中
private   sub   command1_click()
dim   vtag,   vdoc
dim   allcount,   i
list1.clear
set   vdoc   =   webbrowser1.document.all
allcount   =   vdoc.length
for   i   =   0   to   allcount   -   1
if   ucase(vdoc.item(i).tagname)   =   "a "   then   '找到url
vtag   =   vdoc.item(i).href
if   instr(vtag,   "http://ent.163.com/07/0824/08/ ")   then   '检测url中是否含有 "http://ent.163.com/07/0824/08/ "
list1.additem   vdoc.item(i).href   '如果有,则添加到list1中
end   if
end   if
next   i
end   sub
private   sub   form_load()
webbrowser1.navigate   "http://ent.163.com/ "
end   sub

现在想解决的是:
1,将找到的网址分行保存在list.text文件中,而不是放在list1中
2,每隔10分钟刷新一次这个网页后,重新查找符合条件的网址保存在list.text中。如何保证保存的网址和前面的不重复?也就是说10分钟,只添加新的符合条件网址

如能在线指导,感激不尽~~qq   807769484
发表于:2007-08-24 20:33:281楼 得分:0
option   explicit
dim   m   as   long

private   sub   form_load()
webbrowser1.navigate   "http://ent.163.com/ "
timer1.interval   =   60000   '一分钟
end   sub


private   sub   timer1_timer()
if   m   > =   10   then
        webbrowser1.refresh
        m   =   0
else
        m   =   m   +   1
end   if
end   sub

private   sub   webbrowser1_downloadcomplete()
dim   vtag,   vdoc
dim   allcount,   i
'list1.clear
set   vdoc   =   webbrowser1.document.all
allcount   =   vdoc.length
for   i   =   0   to   allcount   -   1
        if   ucase(vdoc.item(i).tagname)   =   "a "   then   '找到url
                vtag   =   vdoc.item(i).href
                if   instr(vtag,   "http://ent.163.com/07/0824/08/ ")   then   '检测url中是否含有 "http://ent.163.com/07/0824/08/ "
                        'list1.additem   vdoc.item(i).href   '如果有,则添加到list1中
                        dim   ifile   as   long
                        ifile   =   freefile
                        open   iif(right(app.path,   1)   =   "\ ",   app.path   &   "list.txt ",   app.path   &   "\list.txt ")   for   append   as   #ifile
                                print   #ifile,   vdoc.item(i).href
                        close   #ifile
                end   if
        end   if
next   i
end   sub


发表于:2007-08-24 20:35:582楼 得分:100
晕!private   sub webbrowser1_downloadcomplete这个段代码需要重写!
打开关闭文件操作放在循环外边
private   sub   webbrowser1_downloadcomplete()
dim   vtag,   vdoc
dim   allcount,   i
'list1.clear
set   vdoc   =   webbrowser1.document.all
allcount   =   vdoc.length
dim   ifile   as   long
ifile   =   freefile
open   iif(right(app.path,   1)   =   "\ ",   app.path   &   "list.txt ",   app.path   &   "\list.txt ")   for   append   as   #ifile

for   i   =   0   to   allcount   -   1
        if   ucase(vdoc.item(i).tagname)   =   "a "   then   '找到url
                vtag   =   vdoc.item(i).href
                if   instr(vtag,   "http://ent.163.com/07/0824/08/ ")   then   '检测url中是否含有 "http://ent.163.com/07/0824/08/ "
                        'list1.additem   vdoc.item(i).href   '如果有,则添加到list1中
                                print   #ifile,   vdoc.item(i).href
                     
                end   if
        end   if
next   i
close   #ifile
end   sub


快速检索

最新资讯
热门点击