【问题标题】:How to get source code of entire content of a webpage programmatically? [closed]如何以编程方式获取网页全部内容的源代码? [关闭]
【发布时间】:2020-12-07 05:50:15
【问题描述】:

我想获取整个页面的源代码,包括动态生成的内容。我试过wininetcurl,但我只是得到了后面代码中呈现的内容。

示例:

正如您在下面看到的,人员列表并未显示为来源。

页面来源:

<!DOCTYPE html>
<html>
<head>
    <title>Presto</title>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <link href="/Content/ie10mobile.css" rel="stylesheet"/>
<link href="/Content/jquery.mobile-1.3.2.css" rel="stylesheet"/>
<link href="/Content/jquery.mobile.structure-1.3.2.css" rel="stylesheet"/>
<link href="/Content/jquery.mobile.theme-1.3.2.css" rel="stylesheet"/>
<link href="/Content/bootstrap.css" rel="stylesheet"/>
<link href="/Content/bootstrap-responsive.css" rel="stylesheet"/>
<link href="/Content/durandal.css" rel="stylesheet"/>
<link href="/Content/toastr.css" rel="stylesheet"/>
<link href="/Content/app.css" rel="stylesheet"/>

    <script type="text/javascript">
        if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
            var msViewportStyle = document.createElement("style");
            var mq = "@-ms-viewport{width:auto!important}";
            msViewportStyle.appendChild(document.createTextNode(mq));
            document.getElementsByTagName("head")[0].appendChild(msViewportStyle);
        }
    </script>
</head>
<body>
    <div id="applicationHost">
        <div class="page-splash"></div>
<div class="page-splash-message">
    Presto
</div>
<div class="progress progress-striped active page-progress-bar">
    <div class="bar" style="width: 100%;"></div>
</div>

    </div>

    <script src="/scripts/jquery-1.9.1.js"></script>
<script src="/scripts/jquery.mobile-1.3.2.js"></script>
<script src="/scripts/knockout-2.2.1.debug.js"></script>
<script src="/scripts/sammy-0.7.4.js"></script>
<script src="/scripts/toastr.js"></script>
<script src="/scripts/Q.js"></script>
<script src="/scripts/breeze.debug.js"></script>
<script src="/scripts/bootstrap.js"></script>
<script src="/scripts/moment.js"></script>

            <script type="text/javascript" src="/App/durandal/amd/require.js" data-main="/App/main"></script>
</body>
</html>

【问题讨论】:

  • 您可以访问该站点的服务器吗?
  • 您可以使用 Wireshark 捕获与服务器之间的所有通信。这将为您提供一切,但您将无法看到生成服务器响应的代码。
  • @Kitiara 那么 Wireshark 应该可以完成这项工作。它纯粹是一个监控实用程序,当与接入以太网流的单独计算机一起使用时,它的存在是不可检测的。我经常使用它来调试或监控各种设备。
  • 哦,所以您想查看由浏览器中的脚本生成的页面的 HTML。 stackoverflow.com/questions/6868577/…

标签: c++ curl wininet


【解决方案1】:

我找到了 2 个解决方案; IWebBrowser2 和 WebView2。

  1. IWebBrowser2 使用的是旧版本的 IE,某些网站需要更高版本。而且没有办法切换到 Edge。有一个注册表技巧,但它实际上并没有改变 IE 的版本。所以这个有点问题。

  2. WebView2 使用的是最新版本的 Microsoft Edge,并且运行良好。周围有几个示例,这是我尝试过的一个:https://github.com/MicrosoftEdge/WebView2Browser

出于某种原因,WebView2 起初无法与我当前的 Microsoft Edge 版本一起使用,然后我安装了 Microsoft Edge Canary Channel 以使其正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-06
    • 1970-01-01
    • 1970-01-01
    • 2021-12-03
    • 1970-01-01
    • 2010-09-20
    • 2012-10-01
    相关资源
    最近更新 更多