Python 3.x 美联能';找不到桌子

Python 3.x 美联能';找不到桌子,python-3.x,beautifulsoup,Python 3.x,Beautifulsoup,我正在尝试从以下链接获取表: 但是,我得到了一个返回的空列表。我在html中查找该网站,我可以看到表标记。拉这些表缺少什么?需要提取表数据,因为数据是通过JavaScript加载的。作为一个例子,我在这里提取表一数据并保存到csv文件 import requests from bs4 import BeautifulSoup from selenium import webdriver import time import pandas as pd pd.set_option('display.

我正在尝试从以下链接获取表:

但是,我得到了一个返回的空列表。我在html中查找该网站,我可以看到表标记。拉这些表缺少什么?

需要提取表数据,因为数据是通过JavaScript加载的。作为一个例子,我在这里提取表一数据并保存到csv文件

import requests
from bs4 import BeautifulSoup
from selenium import webdriver
import time
import pandas as pd
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 1000)

url = 'https://www.nba.com/standings?GroupBy=conf&Season=2019-20&Section=overall'
driver = webdriver.Chrome(r"C:\Users\Subrata\Downloads\chromedriver.exe")
driver.get(url)

soup = BeautifulSoup(driver.page_source, 'html.parser')
tables = soup.select('div.StandingsGridRender_standingsContainer__2EwPy')
table1 = []
for td in tables[0].find_all('tr'):
    first =[t.getText(strip=True, separator=' ') for t in td]
    table1.append(first)


df = pd.DataFrame(table1[1:], columns=table1[0] )

df.to_csv('x.csv')

这可能会有所帮助:看起来该表是通过JavaScript加载的,因此从URL获取数据时很不幸不会包含它。您可以通过打印
请求加载的内容进行检查。这在我的本地计算机上有效,但当我将代码部署到Heroku时,bs4找不到表,并且在尝试循环遍历表时,我会得到一个索引器。你知道为什么会这样吗?
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
import time
import pandas as pd
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 1000)

url = 'https://www.nba.com/standings?GroupBy=conf&Season=2019-20&Section=overall'
driver = webdriver.Chrome(r"C:\Users\Subrata\Downloads\chromedriver.exe")
driver.get(url)

soup = BeautifulSoup(driver.page_source, 'html.parser')
tables = soup.select('div.StandingsGridRender_standingsContainer__2EwPy')
table1 = []
for td in tables[0].find_all('tr'):
    first =[t.getText(strip=True, separator=' ') for t in td]
    table1.append(first)


df = pd.DataFrame(table1[1:], columns=table1[0] )

df.to_csv('x.csv')