如何以编程方式获取网页全部内容的源代码?

问题描述

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

示例:

enter image description here

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

页面源:

<!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>

解决方法

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

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

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

由于某种原因,WebView2最初无法与当前的Microsoft Edge版本配合使用,然后我安装了Microsoft Edge Canary Channel使其能够正常工作。