WinSpider——Windows WebCrawler 应用程序






1.22/5 (22投票s)
2003年2月9日
2分钟阅读

131409

2509
使用C#开发的网页抓取工具 - 这是一个名为WinSpider的前端,该应用程序在后端使用“wget”进行“爬取”操作。它实现了一种简单的并行进程间通信方法。
引言
此应用程序可用于抓取URL内容及其子目录(可选)
该应用程序可以在防火墙后工作,并具有最小化到系统托盘的功能。 进度将在状态窗口(黄色)中更新。
为了允许URL输入,我使用了一个具有历史记录的URL组合框。
此实用程序的后端是wget(开源项目),您可以从http://www.wget.org 获取最新版本
未解决的问题
有人评论说,抓取的目录正在从当前文件夹中删除。(这是一个临时目录,文件首先将被抓取到这里)。
然后复制到指定的目录。(您可以在临时目录中看到它们在抓取过程中)
请删除目录删除部分以保留两个目录的内容,以便以后您可以更快地获取URL的更新版本)。
抓取代码如下所示
这使用了一种并行的进程间通信方式 ;-) void StartLeach()
{
if(urlComboAddress.Text.ToLower() == "http://"
|| urlComboAddress.Text.ToLower() == "ftp://")
{
MessageBox.Show("请指定一个 http:// 或 ftp:// 站点位置。", "错误");
return;
}
if(cCheckEnableProxy.Checked)
{
if( cTextServer.Text == ""
||cTextUser.Text == ""
|| cTextPass.Text == ""
|| cTextPort.Text == "" )
{
MessageBox.Show("请指定正确的代理服务器、端口、用户名和密码。", "错误");
return;
}
}
{
MessageBox.Show("目录不存在");
return;
}
MenuCancel.Enabled = true;
strOutPath = cOutFolder.Text;
cTextOut.Clear();
if(cCheckEnableProxy.Checked)
{
strBatch += " --proxy-user="
+ cTextUser.Text
+ " --proxy-pass=" + cTextPass.Text
+ " -e http_proxy=" + cTextServer.Text
+ ":"+ cTextPort.Text;
}
if(cCheckRecursive.Checked)
{
strBatch += " -r ";
{
strBatch += " -np ";
if(cCheckSiblings.Checked)
{
strBatch+= " -l 1 "; // one level
}
else
{
strBatch+= " -l 0 "; //infinite levels
}
}
// -P prefix
//
strBatch
+= " -o out.cap -N --passive-ftp -x -N -P"
+ strOutPath
+ " "
+ urlComboAddress.Text ;
strBatch+= " ";
if(File.Exists(filename))
{
File.Delete(filename);
}
file.WriteLine(strBatch);
file.Close();
myProcess = new Process();
myProcess.StartInfo.FileName = filename;
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
myProcess.StartInfo.RedirectStandardOutput = false;
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.CreateNoWindow = true;
try
{
cButtonLeach.Enabled = false;
cTimerUpdate.Enabled = true;
myProcess.Start();
}
catch(Exception eProc)
{
MessageBox.Show(eProc.Message);
}
}