怎么取得指定url的网页源码

yesbar 2003-10-09 09:43:51
Dim s As TextReader = New StreamReader(File.Open("c:\index.htm",
FileMode.OpenOrCreate), System.Text.Encoding.Default)
这个可以取得本地计算机的网页源码


请问,我要想取得给定的一个网络上的url呢?如何做?
...全文
69 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
windinwing 2003-10-09
  • 打赏
  • 举报
回复
晕,没分,


public static string getPage(String url)
{
WebResponse result = null;
string txthtml="";
try
{
WebRequest req = WebRequest.Create(url);
result = req.GetResponse();
Stream ReceiveStream = result.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("gb2312");
StreamReader sr = new StreamReader(ReceiveStream,encode);
//this.Message.Text+="\r\n已接收到响应流";
if (true)
{
Char[] read = new Char[256];
int count = sr.Read( read, 0, 256 );

// this.Message.Text+="HTML...\r\n";
while (count > 0)
{
String str = new String(read, 0, count);
txthtml+=str;
count = sr.Read(read, 0, 256);
}
// this.Message.Text="":
}
}
catch(Exception)
{
txthtml="err";
//this.is_id.Value=url;
}
finally
{
if (result != null)
{
result.Close();
}

}
//this.is_id.Value=url;
return txthtml;
}

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧