网络源不显示脚本的内容

时间:2019-06-26 02:08:38

标签: python python-2.7 selenium selenium-chromedriver

我正在尝试编写一个从网站获取数据的脚本,但是遇到了问题。

应该解析页面源代码以获得列标题,但是我正在页面源代码下方而不是“脚本内容”。如何获取显示在浏览器窗口中但页面源中不存在的HTML数据?许多帮助

            <title>QLMM</title>

            <script id="QLMM-ui-bootstrap" src="../../resources/QLMM-ui-core.js" data-QLMM-ui-libs="QLMM.m" data-QLMM-ui-theme="QLMM_belize" data-QLMM-ui-compatversion="edge" data-QLMM-ui-resourceroots="{&quot;qmoverview&quot;: &quot;&quot;}">
            </script><link rel="stylesheet" href="../../resources/QLMM/ui/core/themes/QLMM_belize/library.css" id="QLMM-ui-theme-QLMM.ui.core" data-QLMM-ui-ready="true" /><link rel="stylesheet" href="../../resources/QLMM/m/themes/QLMM_belize/library.css" id="QLMM-ui-theme-QLMM.m" data-QLMM-ui-ready="true" />

            <link rel="stylesheet" type="text/css" href="css/style.css" />

            <script>
                // Register platform module path as local resource
                    if(window.location.hostname==='localhost')
                            jQuery.QLMM.registerModulePath('QLMM.support.qmoverview','webapp');

                    var oCore = QLMM.ui.getCore(),
                            oConfig = oCore.getConfiguration(),
                            aBrowserLanguages = (window.navigator &amp;&amp; window.navigator.languages) || [],
                            aUserLanguages = [oConfig.getLanguage()].concat(aBrowserLanguages),
                            // Filter english locales and get first of them
                            sCoreLanguage = aUserLanguages.filter(function(sLanguage) {
                                    return sLanguage.slice(0, 2) === "en";
                            }).shift();

                    // If not UK english, reset to en
                    if (!sCoreLanguage || sCoreLanguage.toLowerCase() !== "en-gb") {
                            sCoreLanguage = "en";
                    }
                    oCore.getConfiguration().setLanguage(sCoreLanguage);

                    oCore.attachInit(function() {
                            new QLMM.ui.core.ComponentContainer({
                                    height : "100%",
                                    name : "qmoverview"
                            }).placeAt("content");
                    });
            </script>
    <style type="text/css">@font-face {font-family: 'QLMM-icons';src: url('../../resources/QLMM/ui/core/themes/base/fonts/QLMM-icons.woff2') format('woff2'),url('../../resources/QLMM/ui/core/themes/base/fonts/QLMM-icons.woff') format('woff'),url('../../resources/QLMM/ui/core/themes/base/fonts/QLMM-icons.ttf') format('truetype'),local('QLMM-icons');font-weight: normal;font-style: normal;}</style><link rel="stylesheet" href="../../resources/QLMM/ui/unified/themes/QLMM_belize/library.css" id="QLMM-ui-theme-QLMM.ui.unified" data-QLMM-ui-ready="true" /><link rel="stylesheet" href="../../resources/QLMM/ui/fl/themes/QLMM_belize/library.css" id="QLMM-ui-theme-QLMM.ui.fl" data-QLMM-ui-ready="true" /><link rel="stylesheet" href="../../resources/QLMM/ui/dt/themes/QLMM_belize/library.css" id="QLMM-ui-theme-QLMM.ui.dt" data-QLMM-ui-ready="true" /><link rel="stylesheet" href="../../resources/QLMM/ui/rta/themes/QLMM_belize/library.css" id="QLMM-ui-theme-QLMM.ui.rta" data-QLMM-ui-ready="true" /><link rel="stylesheet" href="../../resources/QLMM/ui/layout/themes/QLMM_belize/library.css" id="QLMM-ui-theme-QLMM.ui.layout" data-QLMM-ui-ready="true" /><link rel="stylesheet" href="../../resources/QLMM/f/themes/QLMM_belize/library.css" id="QLMM-ui-theme-QLMM.f" data-QLMM-ui-ready="true" /><link rel="stylesheet" href="../../resources/QLMM/ui/comp/themes/QLMM_belize/library.css" id="QLMM-ui-theme-QLMM.ui.comp" data-QLMM-ui-ready="true" /><link rel="stylesheet" href="../../resources/QLMM/ovp/themes/QLMM_belize/library.css" id="QLMM-ui-theme-QLMM.ovp" data-QLMM-ui-ready="true" /><link rel="stylesheet" href="../../resources/QLMM/ui/vbm/themes/QLMM_belize/library.css" id="QLMM-ui-theme-QLMM.ui.vbm" data-QLMM-ui-ready="true" /><link rel="stylesheet" href="../../resources/QLMM/ushell/themes/QLMM_belize/library.css" id="QLMM-ui-theme-QLMM.ushell" data-QLMM-ui-ready="true" /><link rel="stylesheet" href="../../resources/QLMM/suite/ui/commons/themes/QLMM_belize/library.css" id="QLMM-ui-theme-QLMM.suite.ui.commons" data-QLMM-ui-ready="true" /><link rel="stylesheet" href="../../resources/QLMM/collaboration/themes/QLMM_belize/library.css" id="QLMM-ui-theme-QLMM.collaboration" data-QLMM-ui-ready="true" /><link rel="stylesheet" href="../../resources/QLMM/uxap/themes/QLMM_belize/library.css" id="QLMM-ui-theme-QLMM.uxap" data-QLMM-ui-ready="true" /><link rel="stylesheet" href="css/style.css" data-QLMM-ui-manifest-uid="id-1561512404993-3" data-QLMM-ui-ready="true" /><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /><script src="https://trackingshallwe.hana.ondemand.com/web-client/v3/library-preload.js" data-QLMM-ui-module="QLMM/git/usage/library-preload.js"></script><link rel="stylesheet" href="https://trackingshallwe.hana.ondemand.com/web-client/v3/themes/QLMM_belize/library.css" id="QLMM-ui-theme-QLMM.git.usage" data-QLMM-ui-ready="false" /></head>

    <body class="QLMMUiBody" id="content" role="application" data-QLMM-ui-area="content" style="height: 100%;">

所有非常高没有选择保存的搜索-所有VH事件(0)更新于03:26SaE约会SLA分钟数LeftComponentAlertsStatusProcessing OrgContractIncident Number工作优先级早期采用者CareIRT%APT%ORT%SLA%ActionsEscalatedMore

1 个答案:

答案 0 :(得分:0)

如果您的要求是获取可见文本,而不是HTML源代码,那么您不应该考虑使用page_source属性,但是您需要宁愿identify the "interesting" element并获得{{ 3}}的属性值。

例如,如果您想从网页中获取所有可见的文本,则可以使用//html中的innerText定位它的根目录

from selenium import webdriver

driver = webdriver.Chrome("c:\\apps\\webdriver\\chromedriver.exe")
driver.get("http://example.com")

root = driver.find_element_by_xpath("//html")
print(root.get_attribute("innerText"))

driver.quit()

XPath expression

请参阅enter image description here文章以了解有关XPath定位器的更多信息