求信息采集软件 即思路(顶者有分)

「已注销」 2008-09-18 11:47:15
求信息采集程序开发思路!
有源码更好,发送到邮箱lwp1493@sina.com不胜感激!
...全文
249 28 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
hackztx 2008-09-18
  • 打赏
  • 举报
回复

RMB就帮你写!


远程网址
{
网址可以访问(编码问题,源代码获取异常?怎么样处理源代码,如过滤掉所有的html标记,去除所有的\n之类的。。。。。)
网址不可以访问(访问过快,使服务器端暂时关闭?网址不存在?被重定向等)
}

编写正则(string strHtml)
{
//正则编写错误
//正则获取不到结构
//如何编写最优正则
//获取正则结果
}

//很多方面的因素,比如说你要抓取一个大网站的数据,该网站某个资料有分页,有10页,你抓取了几页后断电了,你如何下次运行程序的时候自动续上
「已注销」 2008-09-18
  • 打赏
  • 举报
回复
如果被采集的页面有图片或是其他附件。这个图片、附件如何处理?
bonnibell 2008-09-18
  • 打赏
  • 举报
回复
自己在网上下东西时常用的

网上有些蜘蛛,爬虫等程序可以参考
wszhoho 2008-09-18
  • 打赏
  • 举报
回复
主要就两个难点,一个是被采集的页面的编码判断,一个是正则匹配,别的,好像没什么复杂的了。
bonnibell 2008-09-18
  • 打赏
  • 举报
回复
引用System.Net 空间

for(int i=1;i<=106;i++)
{

string strUrl = "http://****************/listall.asp?"+i+"&order=id&ifgood=&stype=txt";
WebClient client = new System.Net.WebClient();
  byte[] page=client.DownloadData(strUrl);

string strInputHtml = Encoding.Default.GetString(page);

foreach(Match m in Regex.Matches(strInputHtml,@"(.*)"))
{
try
{
string strRegexResault = m.Groups[1].Value.ToString();
string strName = m.Groups[3].Value.ToString();
//Response.Write(strName);
//Response.Write("
");
strRegexResault = strRegexResault.Insert(0,"http://********8/");
string strSql = "INSERT T_LeasePerson(SubName,FileName) VALUES ('"+strName.Trim()+"','"+strRegexResault.Trim()+"')";
SqlHelper.ExecuteNonQuery(this.ConnStr,CommandType.Text,strSql);
}
catch
{
continue;
}
}
}


正则表达式有待改进:

@"(.*)")

另一个下载文件页面

string strSql = "select ID,SubName,FileName From T_LeasePerson";
SqlDataReader dtrHtml = SqlHelper.ExecuteReader(this.ConnStr,CommandType.Text,strSql);
while (dtrHtml.Read())
{
try
{
WebClient myWebClient = new System.Net.WebClient();
  myWebClient.DownloadFile(dtrHtml[2].ToString(),@"E:\douwn\"+dtrHtml[1].ToString()+dtrHtml[0].ToString()+".html");
}
catch
{
continue;

}
}

1:下页面;
2:用正则解析;
3:保存相关内容
「已注销」 2008-09-18
  • 打赏
  • 举报
回复
源码片段也可!
分不够可以另开一贴!
优途科技 2008-09-18
  • 打赏
  • 举报
回复
顶顶你把。
caofan520 2008-09-18
  • 打赏
  • 举报
回复
发送请求到要采集的页面

返回HTML代码

处理HTML代码

处理完的HTML写入数据库
JeffChung 2008-09-18
  • 打赏
  • 举报
回复
顶,据说有分
GOUXIAOQIANG701222 2008-09-18
  • 打赏
  • 举报
回复
顶顶
yagebu1983 2008-09-18
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 iuhxq 的回复:]
http://www.svnhost.cn/Article/Detail-120.shtml

http://www.svnhost.cn/Article/Detail-116.shtml

http://www.svnhost.cn/Article/Detail-115.shtml

http://www.svnhost.cn/Download/?k=%E8%9C%98%E8%9B%9B
[/Quote]
up!!
a2068879 2008-09-18
  • 打赏
  • 举报
回复
什么东东~~乱
flythere 2008-09-18
  • 打赏
  • 举报
回复
帮你顶下
蓝色木 2008-09-18
  • 打赏
  • 举报
回复
大图片可以试试

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Text;

private void menuItem36_Click(object sender, System.EventArgs e)
{
string FileName;
string Url;
FileName="c:\1.gif";
Url=" if (SavePhotoFromUrl(FileName,Url)){
MessageBox.Show("图片下载成功");
}
else
{
MessageBox.Show("图片下载失败");

}


}

/// <summary>
/// 从图片地址下载图片到本地磁盘
/// </summary>
/// <param name="ToLocalPath">图片本地磁盘地址</param>
/// <param name="Url">图片网址</param>
/// <returns></returns>
public static bool SavePhotoFromUrl(string FileName,string Url)
{
bool Value=false;
WebResponse response = null;
Stream stream = null;

try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);

response = request.GetResponse();
stream = response.GetResponseStream();

if( !response.ContentType.ToLower().StartsWith("text/") )
{
Value=SaveBinaryFile(response,FileName);

}

}
catch(Exception err)
{
string aa=err.ToString();
}
return Value;
}
/// <summary>
/// Save a binary file to disk.
/// </summary>
/// <param name="response">The response used to save the file</param>
// 将二进制文件保存到磁盘
private static bool SaveBinaryFile(WebResponse response,string FileName)
{
bool Value=true;
byte []buffer = new byte[1024];

try
{
if(File.Exists(FileName))
File.Delete(FileName);
Stream outStream =System.IO.File.Create( FileName );
Stream inStream = response.GetResponseStream();

int l;
do
{
l = inStream.Read(buffer,0,buffer.Length);
if(l>0)
outStream.Write(buffer,0,l);
}
while(l>0);

outStream.Close();
inStream.Close();
}
catch
{
Value=false;
}
return Value;
}








本文转自【网上潮州】:http://www.imcz.cn/ShowPost.asp?ThreadID=19694
蓝色木 2008-09-18
  • 打赏
  • 举报
回复
先得到html内容
在用正则分析
是图片就下载
WebClient wc=new WebClient();
wc.DownloadFile("http://community.csdn.net/expert/images/rank/user1.gif",Application.StartupPath+@"\1.gif");

小图片可以这么下载

akt45678 2008-09-18
  • 打赏
  • 举报
回复
我也来顶下。
wjxluck 2008-09-18
  • 打赏
  • 举报
回复
up
wszhoho 2008-09-18
  • 打赏
  • 举报
回复
给你发邮件了
wanjianhong 2008-09-18
  • 打赏
  • 举报
回复
帮顶
加载更多回复(8)

62,244

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧