首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

跪求页面抓取的源代码。(完整),该如何处理

2011-12-30 
跪求页面抓取的源代码。(完整)如T[解决办法]帮顶下下[解决办法]up[解决办法]http://blog.csdn.net/jxufewbt

跪求页面抓取的源代码。(完整)
如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

热点排行