【发布时间】:2017-03-03 05:46:09
【问题描述】:
父链接下的监控选项卡: http://www.pajak.go.id/statistik-amnesti
使用 Python,我正在尝试提取 https://monitoringamnesti.pajak.go.id/viewer/dashboard?dashboardguid=90a16bf8-d418-4ed4-8160-7f883f601dd0&v=636126392121123334&style=Default 的左上角表格
我的代码:
import selenium.webdriver as driver
browser = driver.Chrome()
url= "https://monitoringamnesti.pajak.go.id/viewer/public/dashboard?name=Monitoring_Amnesti_Pajak"
browser.get(url)
all_text = browser.execute_script("returndocument.getElementById('SimpleDataGrid-viewport').textContent")
但是,所有文本都集中在一起。有没有办法可以将表中的所有信息作为列表/数据框获取?
HTML 代码:
<div id="SimpleDataGrid-viewport" class="datagrid-viewport" style="width: 120px; height: 376px;">
<div id="SimpleDataGrid-spacer-clip" class="datagrid-spacer-clip clip _hidden" style="width: 22px; height: 23px;">
<div id="SimpleDataGrid-spacer" class="datagrid-spacer" style="width: 22px; height: 23px;">
<div class="row">
<div class="cell blank" style="border-bottom-color: rgb(0, 153, 195); width: 22px; height: 11px;">
</div>
</div>
</div>
</div>
<div id="SimpleDataGrid-head-clip" class="datagrid-head-clip clip" style="width: 120px; margin-left: 0px; height: 23px;">
<div id="SimpleDataGrid-head" class="datagrid-head" style="top: 0px; left: 0px; width: 552px;">
<div class="row">
<div class="cell column0 text sortable" data-type="text" data-index="0" data-sortorder="unsorted" style="border-bottom-color: rgb(0, 153, 195); width: 161px; height: 11px;">Jenis<em class="unsorted" data-sortorder="unsorted"></em>
</div>
<div class="cell column1 number sortable" data-type="number" data-index="1" data-sortorder="unsorted" style="border-bottom-color: rgb(0, 153, 195); width: 52px; height: 11px;">Juli<em class="unsorted" data-sortorder="unsorted"></em>
</div>
<div class="cell column2 number sortable" data-type="number" data-index="2" data-sortorder="unsorted" style="border-bottom-color: rgb(0, 153, 195); width: 58px; height: 11px;">Agustus<em class="unsorted" data-sortorder="unsorted"></em>
</div>
<div class="cell column3 number sortable" data-type="number" data-index="3" data-sortorder="unsorted" style="border-bottom-color: rgb(0, 153, 195); width: 73px; height: 11px;">September<em class="unsorted" data-sortorder="unsorted"></em></div>
<div class="cell column4 number sortable" data-type="number" data-index="4" data-sortorder="unsorted" style="border-bottom-color: rgb(0, 153, 195); width: 58px; height: 11px;">Oktober<em class="unsorted" data-sortorder="unsorted"></em>
</div>
【问题讨论】:
-
能贴出相关的HTML代码吗?您在问题中提到的链接要求提供登录凭据。
-
嗨,我已经在里面添加了主链接。复制这里的html代码似乎太长太乱了。
标签: html python-2.7 selenium