获取网页的源代码. [英] Get Source Code of Web Page.

查看:118
本文介绍了获取网页的源代码.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在创建Web应用程序.
我需要以字符串格式找到特定

Hi,
I am creating the web application.
I need to find Source Code of a particular

的源代码.
可能吗 ?如果是,怎么办???


提前谢谢!!!!!!!
in String format.
Is it Possible ? If yes than How????


Thanks in advance!!!!

推荐答案

您可以尝试以下代码:

You can try this code:

private string readHtmlPage(string url)
      {
          string result;
          WebResponse objResponse;
          WebRequest objRequest = System.Net.HttpWebRequest.Create(url); // create a request
          objResponse = objRequest.GetResponse(); // get a response

          StreamReader sr = new StreamReader(objResponse.GetResponseStream()); // get the response stream

              result = sr.ReadToEnd(); // read the response stream
              // Close and clean up the StreamReader
              sr.Close();


          return result;
      }


希望这对您有帮助.


Hope this helps.


如果您想在浏览器中显示相同的应用程序代码,
那么您必须使用文件流从您的文件位置读取源文件
If u want to display same code of application in browser
then u have to read source file from ur file location using filestream


XmlDocument doc = new XmlDocument();

doc.Load("http://www.webpath.com");

string sours = doc.tostring();


这篇关于获取网页的源代码.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆