首页 > 解决方案 > selenium phantomjs 在那里但 tbody 丢失

问题描述

抓取此页面时:

https://www.hkex.com.hk/Products/Listed-Derivatives/Equity-Index/Hang-Seng-Index-(HSI)/Hang-Seng-Index-Futures?sc_lang=en#&product=HSI

在谷歌浏览器键 F12 中,我看到了 xpath

  t//*[@id="equity_future"]

有一个thead和一个tbody。tbody 可用。

但是,在 python3 调试器中,使用

wdriver = webdriver.PhantomJS()
wdriver.get(url)
soup = BeautifulSoup(wdriver.page_source,"lxml")

我确实看到了孩子们,但身体似乎是空的

<tbody>
</tbody>

有任何想法吗?

标签: python-3.xselenium-webdriverphantomjs

解决方案


如果您提取仅使用Seleniumpage_source ,您可以找到所有<tbody>标签,如下所示:

  • 代码块:

    driver = webdriver.PhantomJS(executable_path=r'C:\WebDrivers\phantomjs.exe')
    driver.get("https://www.hkex.com.hk/Products/Listed-Derivatives/Equity-Index/Hang-Seng-Index-(HSI)/Hang-Seng-Index-Futures?sc_lang=en#&product=HSI")
    print(driver.page_source)
    
  • 控制台输出片段 1:

    <tbody>
    <tr>
        <td class="ls">Last Traded</td>
        <td class="vo">Volume</td>
        <td class="oi">Prev.Day Open Interest</td>
    </tr>
    </tbody>
    
  • 控制台输出片段 2:

    <tbody>
    <tr>
        <td class="se">Prev.Day Settlement Price</td>
        <td class="vo">Volume</td>
        <td class="oi">Prev.Day Open Interest</td>
    </tr>
    </tbody>
    

推荐阅读