我正在尝试从网页上的特定表格中提取数据。页面上有多个表,所以我试图使用表 ID 仅提取所需的表。
网址:https://basketball.realgm.com/player/Luke-Nelson/Summary/50483
我到目前为止的代码如下。
from urllib.request import urlopen
from bs4 import BeautifulSoup
import pandas as pd
import ssl
# Ignore SSL certificate errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
#URL input
url = 'https://basketball.realgm.com/player/Luke-Nelson/Summary/50483'
html = urlopen(url, context=ctx).read()
soup = BeautifulSoup(html, "html.parser")
table = soup.find('table', id='table-1696')
print(table)
我假设 print 语句会从表中打印 HTML(以前只在一张表上工作)但是当我运行程序时它有以下输出:
最终我的目标是在 python 中重新创建表并导出到 excel,但无法克服第一个障碍!
冉冉说
尚方宝剑之说
一只名叫tom的猫
相关分类