【发布时间】:2021-11-03 10:58:15
【问题描述】:
我有以下代码,但它生成的行包含奇怪的字符,例如 Luka DonÄić 而不是 Luka Dončić。
import pandas as pd
from requests import get
from bs4 import BeautifulSoup
scrapTable = get('https://widgets.sports-reference.com/wg.fcgi?css=1&site=bbr&url=%2Fleagues%2FNBA_2021_per_game.html&div=div_per_game_stats')
scrapTable.encoding = 'utf-8-sig'
soup_a = BeautifulSoup(scrapTable.content, 'html.parser')
table = soup_a.find('table')
df_nba_PerGame = pd.read_html(str(table), encoding='utf8')[0]
知道哪里出了问题吗?
【问题讨论】:
-
如果把
encoding参数去掉pd.read_html,会发生什么? -
什么都没有。
标签: python beautifulsoup utf-8 python-requests