简体   繁体   English

如何在C#中获取网页的完整源代码?

[英]How do I get the full source code of a webpage in C#?

I am working on a little project and it involves getting data from a website to calculate stuff. 我正在做一个小项目,它涉及从网站获取数据来计算内容。

I tried 我试过了

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    StreamReader sr = new StreamReader(response.GetResponseStream());
    rtb_data.Text = sr.ReadToEnd();
    sr.Close();

But this way, I dont get the full source code, like I do when I open the developer kit on chrome for instance (F12). 但是这样一来,我没有得到完整的源代码,就像我在chrome上打开开发人员工具包(F12)一样。

Example: 例:

    <div id="live-match" class="panel-container" data-match-status-code="6" data-mode="3">

I get: 我得到:

    <div id="live-match" class="panel-container">

in that div are many important information but I dont get the classes at all. 在那个div中有许多重要的信息,但是我根本不了解这些课程。

I am no pro with C# or dynamic webpages but since I am able to see the real source code with the developer kit, it should be possible to get it in C# too, right? 我不是C#或动态网页的专业人士,但是由于我能够使用开发人员工具包看到真正的源代码,因此也应该可以在C#中获得它,对吧?

My last solution would be to work with the copy/paste source code and work from there but that would be really slow since I wanna automatically calculate stuff. 我的最后一个解决方案是使用复制/粘贴源代码并从那里开始工作,但这确实很慢,因为我想自动计算内容。

Do you guys have any idea how I can get the full source code? 你们知道我如何获得完整的源代码吗? Do I have to temp download the content maybe? 是否需要临时下载内容? If yes, how? 如果是,怎么办?

The problem you have is that you don't want the source of the web page (that is what you get when you do your simple web request) You seem to actually be after the DOM that is generated at runtime. 您遇到的问题是,您不希望网页的 (这是您执行简单的Web请求时所得到的),您似乎实际上是在运行时生成的DOM之后。

Unfortunately, unless you are willing to write your own browser... 不幸的是,除非您愿意编写自己的浏览器...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM