我正在try 从这个URL中获取数据:https://www2.bmf.com.br/pages/portal/bmfbovespa/lumis/lum-taxas-referenciais-bmf-ptBR.asp

但是,代码的输出只是表头.我找不到另一个URL来放入,当我搜索站点内的表数时,它只返回一个(标题).这是网站的问题,还是我需要做点什么才能拿到位子?

我试着搜索其他URL来填充搜索,但我没有找到任何URL.


import pandas as pd

url = 'https://www2.bmf.com.br/pages/portal/bmfbovespa/lumis/lum-taxas-referenciais-bmf-ptBR.asp'

pd.read_html(url, decimal=',', thousands='.')[0]


推荐答案

页面的Html代码格式确实有误,建议使用beautifulsoup+html5lib解析器获取表格数据:

from io import StringIO

import requests
import pandas as pd
from bs4 import BeautifulSoup

url = "https://www2.bmf.com.br/pages/portal/bmfbovespa/lumis/lum-taxas-referenciais-bmf-ptBR.asp"
table = BeautifulSoup(requests.get(url).content, "html5lib").table

df = pd.read_html(StringIO(str(table)), decimal=",", thousands=".")[0]
print(df.head())

打印:

  Dias Corridos  DI x pré       
  Dias Corridos 252(2)(4) 360(1)
0             1     13.15   0.00
1             3     12.97  19.03
2             7     12.93  13.21
3             9     12.92  14.45
4            14     12.90  13.18

Python相关问答推荐

遵循轮廓中对象方向的计算线

从管道将Python应用程序部署到Azure Web应用程序,不包括需求包

LAB中的增强数组

使用Keras的线性回归参数估计

acme错误-Veritas错误:模块收件箱没有属性linear_util'

删除最后一个pip安装的包

抓取rotowire MLB球员新闻并使用Python形成表格

在Wayland上使用setCellWidget时,try 编辑QTable Widget中的单元格时,PyQt 6崩溃

Julia CSV for Python中的等效性Pandas index_col参数

对所有子图应用相同的轴格式

为什么NumPy的向量化计算在将向量存储为类属性时较慢?'

什么是最好的方法来切割一个相框到一个面具的第一个实例?

如何使用Pandas DataFrame按日期和项目汇总计数作为列标题

CommandeError:模块numba没有属性generated_jit''''

在Python中计算连续天数

语法错误:文档. evaluate:表达式不是合法表达式

提取数组每行的非零元素

浏览超过10k页获取数据,解析:欧洲搜索服务:从欧盟站点收集机会的微小刮刀&

极柱内丢失类型信息""

Polars定制函数返回多列