1. 首先采集下整个网站
private void button1_Click(object sender, EventArgs e)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.textBox1.Text);
WebResponse response = request.GetResponse();
System.IO.Stream strm = response.GetResponseStream();
System.IO.StreamReader sr = new StreamReader(strm, System.Text.Encoding.Default);
this.textBox2.Text = sr.ReadToEnd();
strm.Close();
sr.Close();
}
2. 过滤并显示结果
private void button2_Click(object sender, EventArgs e)
{
string str = this.textBox2.Text.Trim();
//过滤内容
str = Regex.Replace(str, "<script.*?>((/n|/r|.)*?)<///script>", "");
str = Regex.Replace(str, "<input[^>]*>", "");
str = Regex.Replace(str, "<[^>]*>", "{}");
str = Regex.Replace(str, "//s| ", "", RegexOptions.IgnoreCase | RegexOptions.Multiline);
string split = "{}";
string[] arr = str.Split(split.ToCharArray());
foreach (string str1 in arr)
{
this.textBox3.Text += str1; //显示过滤后的结果
}
}
我测试了一下,后来得到的这个数组,如果网页文件太多,经常arr.Length是2000多,那样数据根本就采集不下来,太慢了。
有没有什么好方法优化一下啊。
哎,我怎么过滤,要取的数据量还是很大。
你们可以去看看这个页面 http://www.igxe.com.cn/inc/DisplayOffer.cfm?gid=10
我要取出这个页面显示的所有值,并写入本地数据库。
有谁做过这样大量采集吗
你们可以去看看这个页面 http://www.igxe.com.cn/inc/DisplayOffer.cfm?gid=10
我要取出这个页面显示的所有值,并写入本地数据库。
有谁做过这样大量采集吗
================
这也叫大量?
数据处理上用正则
<td nowrap>.*?229:(.*?)</td>.*?<td>(.*?)</td>.*?<td>(.*?)</td>
组1-3 分别是服务器 价格 数量
还有上面的System.IO.StreamReader sr = new StreamReader(strm, System.Text.Encoding.Default);
改成UTF-8
上面的正则改改
<td nowrap>.*?/d+:(.*?)</td>.*?<td>(.*?)</td>.*?<td>(.*?)</td>