日期:2014-05-19  浏览次数:20438 次

一个简单的网页数据采集,请教大家有什么好方法
客户的需求是,在和他们同类型网站中采集实时的商品及价格。然后与自己的数据进行比对

打个比方说,客户和它的同行的网站中,几乎都有下面这样的表格显示

类别               价格

商品1             2.63元
商品2             3.41元
商品3             1.28元

在这里,商品的种类差不多都是一样的,都是那么几种,但各网站可能有不同的表现方法,
有的是用
<table>
<tr> <th> 类别 </th> <th> 价格 </th>
<tr> <td> 商品1 </td> <td> 2.63元 </td>
</table>
有的是用div的无序列表来显示。

而且出现的文字形式也有可能不同,例如:

类别               价格

商品一           $2.63
商品二           $3.41
商品三           $1.28

----------------------

我想先实现一个DEMO,大家看看怎么实现

假如有一个TextBox为txtUrl,输入客户同行的网站URL
   
然后将采集回来的数据经过过滤,返回“类别”和“价格”两种数据,然后写入到数据库

大家给提供个思路,以及关键的类和方法。有示例代码更好。

------解决方案--------------------
//昨天刚写的一个临时用来学习的.你参考一下. using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Net; using System.Text.RegularExpressions; using System.Xml; using System.IO; namespace GetQ { /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; private System.Windows.Forms.RichTextBox txtLog; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1)); this.button1 = new System.Windows.Forms.Button(); this.txtLog = new System.Windows.Forms.RichTextBox(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(424, 464); this.button1.Name = "button1 "; this.button1.TabIndex = 0; this.button1.Text = "开始 "; this.button1.Click += new System.EventHandler(this.button1_Click); // // txtLog // this.txtLog.Location = new System.Drawing.Point(32, 48); this.txtLog.Name = "txtLog "; this.txtLog.Size = new System.Drawing.Size(608, 360); this.txtLog.TabIndex = 1; this.txtLog.Text = " "; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(728, 525); this.Controls.Add(this.txtLog); this.Controls.Add(this.button1); this.Icon = ((System.Drawing.Icon)(resources.GetObject( "$this.Icon "))); this.Name = "Form1 "; this.Text = "数据抓取 "; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); } #endregion private WebClient c = null; void DoGet() { string Url = "http://www.gdgajj.com/wzks/index.jsp "; //WebClient c = new WebClient(); byte[] b = this.c.DownloadData(Url); string strOrgHTML = System.Text.Encoding.Default.GetString(b); Regex reg = new Regex