string OpenUrlSource(string url)
{
if (url == null || url.Trim() == "")
return null;
WebClient wc = new WebClient();//定义
wc.Credentials = CredentialCache.DefaultCredentials;
wc.OpenRead(url);
Byte[] pageData = wc.DownloadData(url);
return Encoding.UTF8.GetString(pageData);//.ASCII.GetString }
上面的代码我想查看指定网址的源文件,但是查看的结果是:<script type=\"text/javascript\"> top.location.href = \"http://app.baidu.com/widget?appid=104160\";</script>。而不是网页右键->查看源文件,显示的信息。求高手帮忙解答,有没有其他读取网页html文件的代码?上面的方法我实在不知道有什么问题。
{
if (url == null || url.Trim() == "")
return null;
WebClient wc = new WebClient();//定义
wc.Credentials = CredentialCache.DefaultCredentials;
wc.OpenRead(url);
Byte[] pageData = wc.DownloadData(url);
return Encoding.UTF8.GetString(pageData);//.ASCII.GetString }
上面的代码我想查看指定网址的源文件,但是查看的结果是:<script type=\"text/javascript\"> top.location.href = \"http://app.baidu.com/widget?appid=104160\";</script>。而不是网页右键->查看源文件,显示的信息。求高手帮忙解答,有没有其他读取网页html文件的代码?上面的方法我实在不知道有什么问题。
{ System.Net.WebRequest wReq = System.Net.WebRequest.Create(Url);
System.Net.WebResponse wResp = wReq.GetResponse();
System.IO.Stream respStream = wResp.GetResponseStream();
System.IO.StreamReader reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("gb2312"));
string UrlName = reader.ReadToEnd();
return UrlName;
}调用 string s= aa("http://www.baidu.com");是不是这样的