打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
用C#做一个网页数据采集工具_安全中国 -2
用C#做一个网页数据采集工具
安全中国 www.anqn.com
更新时间:2010-06-19 04:24:30
责任编辑:池天
热 点:
if (!worker.CancellationPending)
{
if (Urls[i] == "")
return;
html = inc.GetHtml(Urls[i]);//获取该url的html代码
DataRow NewRow = dt2.NewRow();
//产品名
string ProductName = html.Substring(html.IndexOf("")).Trim();
//产品编号
NewRow["ModelId"] = NewRow["ProductName"].ToString().Substring(NewRow["ProductName"].ToString().IndexOf("Model:") + 6).Trim();
//产品介绍,这些都是根据不同网站的html做相应的修改
string Introduce = html.Substring(html.IndexOf("Product Details") + 26);
Introduce = Introduce.Remove(Introduce.IndexOf("") + 8).Trim()
NewRow["Introduce"] = Introduce;
http://study.pctoday.net.cn/Article/自己用CSharp做一个网页数据采集工具.html
http://www.egacn.com/" title="Replica Watches:">Replica Watches Buy Full Quality Popular Luxury Watches at Amazing Price, Your One Stop Discount Swiss Watches StoreExclusive Replica Rolex Watches, Tag Heuer Watches Replica, Cartier Watches online Sale!http://www.yuget.nethttp://study.pctoday.net.cn/1_ASP.aspxhttp://study.pctoday.net.cn/
文章来源: http://study.pctoday.net.cn/Article/自己用CSharp做一个网页数据采集工具.html
//下载图片
string ProductImage = html.Substring(html.IndexOf("align=center>
ProductImage = textBox2.Text.Trim() + ProductImage.Substring(ProductImage.IndexOf("src=\"") + 5);
ProductImage = ProductImage.Remove(ProductImage.IndexOf("\""));
try
{
inc.DownFile(ProductImage, ImageDir + ProductImage.Substring(ProductImage.LastIndexOf("/") + 1));
}
catch (Exception)
{
ErrorStr.Append("下载图片失败,图片地址:" + ImageDir + ProductImage.Substring(ProductImage.LastIndexOf("/") + 1) + "\r\n");
}
dt2.Rows.Add(NewRow);
//Thread.Sleep(100);
worker.ReportProgress((i + 1) * 100 / Urls.Length, i);
toolStripStatusLabel1.Text = "处理进度:" + (i + 1).ToString() + "/" + Urls.Length.ToString();//进度条
}
}
catch (Exception err)
{
ErrorStr.Append("采集错误:" + err.Message + ";网址:" + Urls[i] + "\r\n");
}
}
da.Update(dt2);
DataBind(dt2);
ShowError(ErrorStr.ToString());
}
///
/// ASPX页面生成静态Html页面
///
public static string GetHtml(string url)
{
StreamReader sr = null;
string str = null;
//读取远程路径
WebRequest request = WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(response.CharacterSet));
str = sr.ReadToEnd();
sr.Close();
return str;
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
关于JSP静态化与伪静态的简单做法
aspx不显示ViewState的实例
通过JAVA bean查询ip归属地,身份证号码信息,手机号码归属地
在HTML中获取地址栏中传递的参数
两种防刷新的高亮导航菜单制作 记录cookies和根据Url网址
C#抓取网页数据分析
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服