日期:2014-05-18  浏览次数:20440 次

跪求页面抓取的源代码。(完整)
如T

------解决方案--------------------
帮顶下下
------解决方案--------------------
up
------解决方案--------------------
http://blog.csdn.net/jxufewbt/archive/2007/08/10/1736961.aspx
------解决方案--------------------
public class HttpSpider
{
public HttpSpider(string url, int timeout):this(new Uri(url),timeout)
{

}
public HttpSpider(Uri url, int timeout)
{
this.Url = url;
this.Timeout = timeout;
}
private Uri _url;

public Uri Url
{
get { return _url; }
set { _url = value; }
}
private int _timeout;

public int Timeout
{
get { return _timeout; }
set { _timeout = value; }
}
private string _resultstr;

public string Resultstr
{
get { return _resultstr; }
set { _resultstr = value; }
}
public void GetWebContent()
{

string strResult = " ";
if (null == this.Url || 0 == this.Timeout)
{
return;
}
try
{

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.Url);
//声明一个HttpWebRequest请求
request.Timeout = this.Timeout;
//设置连接超时时间
request.Headers.Set( "Pragma ", "no-cache ");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream streamReceive = response.GetResponseStream();
StreamReader streamReader = new StreamReader(streamReceive, Encoding.Default);
strResult = streamReader.ReadToEnd();

}
catch
{
}

this.Resultstr = strResult;
}
}
------解决方案--------------------
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
string url = "http://community.csdn.net/Expert/topic/5733/5733418.xml?temp=.9316522 "
// Open a stream to point to the data stream coming from the Web resource.
Stream myStream = myWebClient.OpenRead(url);

Console.WriteLine( "\nDisplaying Data :\n ");
StreamReader sr = new StreamReader(myStream);
Console.WriteLine(sr.ReadToEnd());


// Close the stream.
myStream.Close();
------解决方案--------------------
学习
------解决方案--------------------
up