簡體   English   中英

我如何使用python和beautifulsoup從嵌入html的Excel工作表中提取數據?

[英]How can i extract data from an excel sheet embedded in html using python and beautifulsoup?

因此,我想到了從網頁上的表中提取數據的想法,這樣我就可以對它進行平均,直觀地表示並使用它。 我嘗試將python與beautifulsoup結合使用來獲取數據,但最終還是出現了如下這樣的奇怪的excel格式化代碼:

<!--table
    {mso-displayed-decimal-separator:"\.";
    mso-displayed-thousand-separator:"\,";}
@page
    {margin:1.0in .75in 1.0in .75in;
    mso-header-margin:.51in;
    mso-footer-margin:.51in;}
.style0
    {mso-number-format:General;
    text-align:general;
    vertical-align:bottom;
    white-space:nowrap;
    mso-rotate:0;
    mso-background-source:auto;
...(more of the same)
...

-->

我查看了頁面的源代碼,其中包括:

<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 14">

我該如何以有意義的方式提取數據,保留並允許對其進行操作? 感謝您的時間。

我當前的腳本僅使用curl獲取html文件,然后打開html文件並在其上使用beautifulsoup get_text,並將其保存到文本文件中。

你在做這樣的事情嗎:

 import BeautifulSoup
 s = BeautifulSoup.BeautifulSoup(html)
 table = s.find("table", {"id": "mytableid"})
 try:
     rows = table.findAll('tr')
     for tr in rows:
         cols = tr.findAll('td')
         for td in cols:
             val = td.text

在您改善問題之前,我無法給您更好的答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM