pd.read_html 在 Microsoft Edge 中有效但在 Chrome 中无效

pd.read_html works in Microsoft Edge but not in Chrome

这个简单的代码在 Microsoft Edge 中有效,但在 Chrome 中无效(均使用 Jupyter):

import pandas as pd
url_Chelsea = "https://en.wikipedia.org/wiki/List_of_Chelsea_F.C._seasons"

df_Chelsea=pd.read_html(url_Chelsea)[2]
df_Chelsea

正在获取错误消息(消息结尾):

/opt/conda/lib/python3.6/site-packages/pandas/compat/__init__.py in raise_with_traceback(exc, traceback)
    338         if traceback == Ellipsis:
    339             _, _, traceback = sys.exc_info()
--> 340         raise exc.with_traceback(traceback)
    341 else:
    342     # this version of raise is a syntax error in Python 3

URLError: <urlopen error Tunnel connection failed: 403 Forbidden>

试试这个:

import pandas as pd
import requests

url_Chelsea = "https://en.wikipedia.org/wiki/List_of_Chelsea_F.C._seasons"
proxyDict = { 
          'http'  : "add http proxy", 
          'https' : "add https proxy"
        }

requests.get(url_Chelsea , proxies=proxyDict)

df_Chelsea=pd.read_html(page)[2]
print(df_Chelsea)

有关 proxies 的更多信息,请访问 here