超级菜鸟问题。我正在为自己的幻想足球选秀做准备,而不是从我想要编写脚本的网站上复制/粘贴排名,以节省将来的时间。我正在查看yahoo的排名,当您在表格上方的选择器中选择不同的位置(“ QB”,“ RB”,“ WR”等)时,会有一张表格发生变化。网址没有变化,但是我的脚本只给了我第一个表(“ QB”)数据。如何编写此代码以包含其他“隐藏”表?
import re
from urllib.request import urlopen
from bs4 import BeautifulSoup
url = "https://sports.yahoo.com/nfl/fantasy-rankings/"
html = urlopen(url)
soup = BeautifulSoup(html, 'lxml')
rows = soup.find_all('tr')
list_rows = []
for row in rows:
cells = row.find_all('td')
str_cells = str(cells)
clean = re.compile('<.*?>')
clean2 = (re.sub(clean, '',str_cells))
list_rows.append(clean2)
df = pd.DataFrame(list_rows)
df1 = df[0].str.split(',', expand=True)