还是前面问的问题,
for(int i=0;i<listView1.Items.Count;i++)
{
//listView1.Items.Count>=100
string url = this.listView1.Items[i].SubItems[2].Text.Trim()//取得url地址
再怎么样去获取源代码保存倒数据库.
}
一下就搞的我死机了啊!
#region//取得网页源码
private string GetHTML(string url)
{
System.Net.WebClient client = new System.Net.WebClient();
try
{
byte[] buf = client.DownloadData(url);
return System.Text.Encoding.Default.GetString(buf);
}
catch( Exception er)
{
MessageBox.Show(er.ToString());
}
}
#endregion
for(int i=0;i<listView1.Items.Count;i++)
{
//listView1.Items.Count>=100
string url = this.listView1.Items[i].SubItems[2].Text.Trim()//取得url地址
再怎么样去获取源代码保存倒数据库.
}
一下就搞的我死机了啊!
#region//取得网页源码
private string GetHTML(string url)
{
System.Net.WebClient client = new System.Net.WebClient();
try
{
byte[] buf = client.DownloadData(url);
return System.Text.Encoding.Default.GetString(buf);
}
catch( Exception er)
{
MessageBox.Show(er.ToString());
}
}
#endregion
http://dotnet.aspx.cc/ShowDetail.aspx?id=0A6660CE-4138-41EF-B882-15DB65564709
http://dotnet.aspx.cc/ShowDetail.aspx?id=9D49B3EF-0F91-421B-841F-5D9A000BDA04
办法是很多
http://dotnet.aspx.cc/ShowDetail.aspx?id=4AE836F8-CCB4-4BEF-90B1-25BB1A5E6433
不会是不知道怎么存到数据库吧?
{ string strResult; try
{ HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(a_strUrl); myReq.Timeout = timeout; HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse(); Stream myStream = HttpWResp.GetResponseStream(); StreamReader sr = new StreamReader(myStream, Encoding.Default); StringBuilder strBuilder = new StringBuilder(); while (-1 != sr.Peek())
{ strBuilder.Append(sr.ReadLine() + "\r\n"); } strResult = strBuilder.ToString(); } catch (Exception exp)
{ strResult = "错误:" + exp.Message; }
return strResult;
}
这段代码可以用哈,我正用这段代码监视东西呢
我可以确定不是死循环,因为我采集本地的就要好点,勉强可以,但是一采集网络的就完了!
谢谢你!获取源代码的这部分已经实现了,现在就是要想办法,一下获取100多张的网页源代码
呵呵!我也这样想的,但是我是菜鸟,不知道具体怎么来实现,下面是我的代码
form1里面:
public delegate void GetThreadHTMLlist(string url) ; #region //多线程实现网页源码的获取
void GetThreadHTML(string url)
{
System.Net.WebClient client = new System.Net.WebClient();
try
{
byte[] buf = client.DownloadData(url);
gloab.HtmlSource.Add(System.Text.Encoding.Default.GetString(buf));
}
catch( Exception er)
{
MessageBox.Show(er.ToString());
}
}
#endregion for(int i=0;i<listView1.Items.Count;i++)
{
try
{
threadadd hostping = new threadadd();
hostping.url = this.listView1.Items[i].SubItems[2].Text.Trim();
hostping.getcode = new GetThreadHTMLlist(GetThreadHTML);
mythread[i] = new Thread (new ThreadStart (hostping.threadStart)) ;
//初始化一个线程实例
mythread[i].Start ( ) ;
}
catch(Exception er)
{
MessageBox.Show(er.ToString());
}
}
---------------------------------------------------------------------
下面是一个类:threadadd
using System;namespace Rain
{
/// <summary>
/// threadadd 的摘要说明。
/// </summary>
public class threadadd
{ public string url;
public GetThreadHTMLlist getcode;
public void threadStart()
{
getcode(url);
}
public threadadd()
{
}
}
}
这个是我看人家的代码,写的
using System;namespace Rain
{
/// <summary>
/// gloab 的摘要说明。
/// </summary>
public class gloab
{
public static System.Collections.ArrayList HtmlSource=new System.Collections.ArrayList();
public gloab()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
}
}