【问题标题】:A problem with web scraping using python ,BeautifulSoup and pandas 'read_html'使用 python、BeautifulSoup 和 pandas 'read_html' 进行网页抓取的问题
【发布时间】:2020-05-29 11:10:53
【问题描述】:

感谢大家的帮助!

我正在抓取一张关于 covid19 的数据表并将其推送到 pandas 数据框中,它一直工作到今天早上。

那个代码:

import pandas as pd
import requests
from bs4 import BeautifulSoup


url = 'https://www.worldometers.info/coronavirus/'

req = requests.get(url)

page = BeautifulSoup(req.content, 'html.parser')

table = page.find_all('table',id="main_table_countries_today")[0]

print(table)

df = pd.read_html(str(table))[0]

今天早上我开始收到下一个错误:

ValueError: No tables found matching pattern '.+'

你能帮我弄清楚吗?

【问题讨论】:

  • 这段代码对我来说很好用。返回数据帧列表。
  • 我在不同的 ide 上遇到同样的错误,你能告诉我你从代码中得到了什么吗?
  • 安装 covid19 库。更好pip install COVID19Pyhttps://pypi.org/project/COVID19Py/
  • @ZurHanin - 不确定是什么问题。你能检查一下 lxml 和 html5lib 的 lib 版本吗?
  • 谢谢您,您的 api 是一个非常好的来源,但我需要理解我在代码中做错了什么......

标签: python pandas beautifulsoup


【解决方案1】:

尝试将最后一行更改为:df = pd.read_html(str(table), displayed_only=False)[0] url 处的表头已将其样式属性更改为 style="width:100%;margin-top: 0px !important;display:none;"。以前它没有设置“显示”标签。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-04
  • 2021-01-31
相关资源
最近更新 更多