div标签没有填充,使用selenium python,内部HTML

时间:2016-02-07 08:11:42

标签: python selenium innerhtml

我正在尝试访问下一页div标签中看似隐藏的表:

whoscored.com

...在“传递”链接下

from selenium import webdriver

driver = webdriver.Chrome()
base_url = "https://www.whoscored.com/Matches/959574/LiveStatistics/England-Premier-League-2015-2016-West-Bromwich-Albion-Stoke"
driver.get(base_url)

首先我点击链接:

elem = driver.find_element_by_link_text("Passing")
elem.click()
driver.implicitly_wait(10)

接下来,我尝试获取此表所在的标记的innerhtml。

demo_div = driver.find_element_by_id("live-player-home-passing")
print demo_div.get_attribute('innerHTML')
print driver.execute_script("return arguments[0].innerHTML", demo_div)

但是innerhtml在该标签中显示为空。非常令人沮丧,因为我看到了页面上的数据,但却找不到抓住它的方法。

有什么想法吗?我非常感谢任何帮助。

编辑:这是HTML:

<div id="live-player-home-passing" class="statistics-table-tab">
  <div id="statistics-table-home-passing-loading"></div>
  <div id="statistics-table-home-passing"></div>
  <div id="statistics-table-home-passing-column-legend"></div>
</div>

数据在第3个标签内,但仅在我执行“检查元素”时可见:

<div id="live-player-home-passing" class="statistics-table-tab" style="display: block;">
    <div id="statistics-table-home-passing" data-fwsc="1">
        <table id="top-player-stats-summary-grid" class="grid with-centered-columns hover">
            <thead id="player-table-statistics-head">
            .....

            </thead>
        </table>
    </div>

1 个答案:

答案 0 :(得分:0)

源代码来自服务器并检查其浏览器对信息的表示

尝试直接从webelement获取innerHTML而不是js脚本

table = driver.find_element_by_id("top-player-stats-summary-grid");