如何使用Python selenium从不在源代码页上的网页访问文本?

2024-09-27 23:28:41 发布

您现在位置:Python中文网/ 问答频道 /正文

这是运行javascript的html代码的一部分。我正在尝试访问来自此脚本的文本。当我做'检查元素',我能够看到我需要的文本。但是,当我去查看网页源代码或driver.page\u源,它不在那里-只有这个javascript在那里。有没有办法运行这个javascript,这样我就可以抓取它在网页上显示的文本?你知道吗

以下是在源代码页面中没有显示的Inspect元素代码。我正在尝试访问粗体文本:

<table id="invoiceHistoryTable" class="display dataTable no-footer" cellspacing="0" width="100%" role="grid" aria-describedby="invoiceHistoryTable_info"> <tbody> <tr role="row" class="odd"> <td class="sorting_1">**4/11/2019 04:12:43 PM**</td><td>291321</td><td>- -</td><td>**Invoice uploaded from file=93564LedesInvoiceAnsi.txt.**</td> </tr> <tr role="row" class="even"> <td class="sorting_1">**4/11/2019 04:19:57 PM**</td><td>291321</td><td>- -</td><td>**Client retrieved invoice for processing.**</td> </tr> <tr role="row" class="odd"> <td class="sorting_1">**4/17/2019 04:05:19 PM**</td><td>291321</td><td>- -</td><td>**Invoice approved.**</td></tr> </tbody> <thead> <tr role="row"><th id="header0" class="sorting_asc" tabindex="0" aria-controls="invoiceHistoryTable" rowspan="1" colspan="1" data-column-index="0" aria-label="Date: activate to sort column descending" aria-sort="ascending">Date</th><th id="header1" class="sorting_disabled" rowspan="1" colspan="1" data-column-index="1" aria-label="Invoice No">Invoice No</th><th id="header2" class="sorting_disabled" rowspan="1" colspan="1" data-column-index="2" aria-label="User">User</th><th id="header3" class="sorting_disabled" rowspan="1" colspan="1" data-column-index="3" aria-label="Description">Description</th></tr> </thead></table>

这是页面的源代码和javascript代码:

<div class="roundedBoxContent"> <table id="invoiceHistoryTable" class="display" cellspacing="0" width="100%"> <thead> <tr> <th id="header0">Date</th> <th id="header1">Invoice No</th> <th id="header2">User</th> <th id="header3">Description</th> </tr> </thead> </table> </div> <script type="text/javascript"> jQuery(function() { setupDatePicker("dateStart", "dateEnd"); }); setCurrentPageSizeInDropdown(); var parameters= {"vendorId" : "379863141", "uniqueId" : "6cebf4f4340ccb1f9efcfafab51e28ea", "role" : "6", "buttonText" : { "defaultViewButtonText" : "Default View", "doneButtonText" : "Done" }, "clearButton" : { "buttonId" : "clear", "formId" : "searchForm", "filtersClass" : "filters", "tableId" : "invoiceHistoryTable" },"tooltips" : { "showHideTooltip" : "Show/Hide Columns", "exportExcelTooltip" : "Export to Excel", "exportPdfTooltip" : "Export to PDF", "printTooltip" : "Print", "viewEditTooltip" : "", "viewTooltip" : "" } }; jQuery(".chosen-select").chosen({ width: "20%" }); invoiceHistoryTable.loadVendorLevelTable(parameters); </script>

Tags: 文本idtablecolumninvoicejavascripttrclass

热门问题