Lxml找不到页面上的所有表?

2024-06-16 11:32:27 发布

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

我试图得到一些数据,当我使用lxml时,它找到了2个表,而不是我想要的第3个表。我怀疑这与xpath或生成特定表的方式有关。在

我想从:http://web.tmxmoney.com/pricehistory.php?qm_symbol=WDO.DB.A获取价格历史记录

以下是我的不同尝试和结果。在

import requests
from lxml import html

def financialPriceData():
        priceData = requests.get('http://web.tmxmoney.com/pricehistory.php?qm_symbol=WDO.DB.A')
        PriceScraperTree = html.fromstring(priceData.content)
        #PriceTreeTickers = PriceScraperTree.xpath('//*[@id="innerContent"]/div[4]/div[1]/div[1]/div[1]/table/tbody/tr[1]/td/table/tbody/tr[5]/td/table/tbody/tr/td/table/tbody/tr[2]/td[1]/text()') # no luck. From Chrome.
        # PriceTreeTickers = PriceScraperTree.xpath('//table[@id="qm_history_historyContent"]') # no luck, can't find the table
        PriceTreeTickers = PriceScraperTree.xpath('//table')  # no luck, finds only 2 tables top of the page and bottom of the page data. When I look at text result the daily price is missing.
        print(PriceTreeTickers)

financialPriceData()

Tags: thenodivwebhttptablelxmlxpath