【问题标题】:How to scrape a table with a blind caption?如何用盲标题刮桌子?
【发布时间】:2017-12-06 15:39:29
【问题描述】:

我正在从页面中抓取表格。

但表格的标题是“盲目的”。

有没有办法从站点中提取表格?

像这样使用 BeautifulSoup:

from urllib.request import urllib
from bs4 import BeautifulSoup

【问题讨论】:

标签: python beautifulsoup caption


【解决方案1】:

看看这个:

import bs4 as bs
import urllib.request

link = 'http://companyinfo.stock.naver.com/v1/company/c1010001.aspx?cn=&cmp_cd=005930&menuType=block'
source = urllib.request.urlopen(link)

soup = bs.BeautifulSoup(source, 'html.parser')

table = soup.find('table', attrs={'id' : 'cTB24'})

for tr in table.find_all('tr'):
    for td in tr.find_all('td'):
        print(td.text)

【讨论】:

    猜你喜欢
    • 2015-02-25
    • 1970-01-01
    • 2019-03-25
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    相关资源
    最近更新 更多