发新话题
打印

【转帖】用PB编写一个简单的网络信息收集小工具

【转帖】用PB编写一个简单的网络信息收集小工具

用PB编写一个简单的网络信息收集小工具软件
  inet非可视对象是PB中提供的专门用来和Internet交互的对象,使用该对象可以编写Internet处理程序。该对象使用时,需要首先创建一个继承自InternetResult对象的用户自定义对象,在该自定义对象上编写脚本对从Internet上返回的结果进行处理。下面我们给出一个实例,该实例从企业黄页之类的网站中获取各个企业的信息,保存到本地计算机中。这样的软件对于从事电话推销的公司是非常需要的。
  按照以下步骤开发该软件:
1、创建一个Standard Class,选择InternetResult对象,然后在该对象缺省函数InternetData中编写如下脚本(我们希望将获取到的内容保存到文件中,文件的格式是HTML的):
String ls_filename
string ls_content
integer li_FileNum
integer li_pos1,li_pos2
ls_content = string(data)
li_pos1 = Pos(ls_content,'<table align=center border=0 cellpadding=0 cellspacing=1>')
li_pos2 = Pos(ls_content,'联系人')
li_pos2 = pos(ls_content,'</table>',li_pos2) + len('</table>') - 1
ls_content = Mid(ls_content,li_pos1,li_pos2 - li_pos1)
if Pos(ls_content,'010') > 0 then
ls_filename = String(now(),'hhmmss') + right('00000' + string(rand(100)),3) + '.htm'
li_FileNum = FileOpen("d:\data\" + ls_filename, &
StreamMode!, Write!, Shared!, Replace!)
FileWrite(li_FileNum, ls_content)
FileClose(li_FileNum)
end if
Return 1
保存该用户对象,命名为n_ir_msgbox。     
2、创建一个窗口,提供用户操作界面。非常简单的一个窗口,命名为w_main,在该窗口中定义一个窗口实例变量:
n_ir_msgbox iir_msgbox
在该窗口上放置一个命令按钮,在命令按钮的Clicked事件中编写如下教本:
inet linet_base
String ls_url
long ll_index
SetPointer(HourGlass!)
ls_url = 'http://www.6608.net/qy-ml/view_epinfo_vip.php?id='
iir_msgbox = CREATE n_ir_msgbox
if GetContextService("Internet", linet_base) = 1 THEN
For ll_index = 21272 to 1 step -1
This.Text = String(ll_index)
linet_base.GetURL(ls_url + String(ll_index), iir_msgbox)
next
END IF
DESTROY iir_msgbox

相信上面的程序,如果你能够真正理解,可以改造或者编写成非常使用的网络信息处理程序。
转载 http://www.study01job.com/pb/book/list.php?form=all

TOP

发新话题