【问题标题】:Getting "no table found" error when web scraping with pandas in python 3.7在 python 3.7 中使用 pandas 进行网络抓取时出现“找不到表”错误
【发布时间】:2019-12-17 23:15:14
【问题描述】:

我想从网站中提取各种统计数据。不幸的是,pandas 无法识别提供的表格。这是我的代码:

url = 'https://u.gg/lol/champions/aurelionsol/matchups/'
html = requests.get(url).content
df_list = pd.read_html(html)

ValueError: No tables found

提前感谢您的帮助。

【问题讨论】:

  • 因为它不是html表格而是Javascript,所以你需要使用selenium来抓取这种内容:stackoverflow.com/questions/53239392/…
  • 点击答案旁边的耐克标记,如果对您有帮助,请随时接受我的回答

标签: pandas web-scraping python-requests python-3.7 valueerror


【解决方案1】:

您可以直接使用API

import requests

r = requests.get(
    'https://static.u.gg/assets/lol/riot_static/9.24.1/data/en_US/champion.json?v9.24.2').json()

print(r.keys())

或者你可爱的目标:

import pandas as pd


df = pd.read_json(
    'https://static.u.gg/assets/lol/riot_static/9.24.1/data/en_US/champion.json?v9.24.2')

print(df)

输出:

             type  ...                                               data
Aatrox   champion  ...  {'version': '9.24.1', 'id': 'Aatrox', 'key': '...
Ahri     champion  ...  {'version': '9.24.1', 'id': 'Ahri', 'key': '10...
Akali    champion  ...  {'version': '9.24.1', 'id': 'Akali', 'key': '8...
Alistar  champion  ...  {'version': '9.24.1', 'id': 'Alistar', 'key': ...
Amumu    champion  ...  {'version': '9.24.1', 'id': 'Amumu', 'key': '3...
...           ...  ...                                                ...
Zed      champion  ...  {'version': '9.24.1', 'id': 'Zed', 'key': '238...
Ziggs    champion  ...  {'version': '9.24.1', 'id': 'Ziggs', 'key': '1...
Zilean   champion  ...  {'version': '9.24.1', 'id': 'Zilean', 'key': '...
Zoe      champion  ...  {'version': '9.24.1', 'id': 'Zoe', 'key': '142...
Zyra     champion  ...  {'version': '9.24.1', 'id': 'Zyra', 'key': '14...

[147 rows x 4 columns]

【讨论】:

    猜你喜欢
    • 2022-12-18
    • 2021-10-10
    • 1970-01-01
    • 2021-06-01
    • 2016-08-18
    • 2020-07-06
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多