Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取动态表数据_Python_Parsing_Web Scraping_Beautifulsoup_Lxml - Fatal编程技术网

Python 获取动态表数据

Python 获取动态表数据,python,parsing,web-scraping,beautifulsoup,lxml,Python,Parsing,Web Scraping,Beautifulsoup,Lxml,我有以下代码: url = 'https://www.basketball-reference.com/leagues/NBA_2017_standings.html#all_expanded_standings' html = urlopen(url) soup = BeautifulSoup(html, 'lxml') print(len(soup.findAll('table'))) print(soup.findAll('table')) 网页上有6个表,但只返回4个表。我尝试使用'

我有以下代码:

url = 'https://www.basketball-reference.com/leagues/NBA_2017_standings.html#all_expanded_standings'
html = urlopen(url)
soup = BeautifulSoup(html, 'lxml')

print(len(soup.findAll('table')))
print(soup.findAll('table'))
网页上有6个表,但只返回4个表。我尝试使用'html.parser'或'html5lib'作为解析器,但都不起作用

你知道我如何从网页上获得“扩展排名”表格吗


谢谢

请求
无法获取由
JS
加载的数据。因此,您必须使用
selenium
。首先通过
pip
-
pip安装selenium
安装
selenium
,然后下载并将文件放在您的工作目录中。然后尝试以下代码

from bs4 import BeautifulSoup
import time
from selenium import webdriver

url = "https://www.basketball-reference.com/leagues/NBA_2017_standings.html"
browser = webdriver.Chrome()

browser.get(url)
time.sleep(3)
html = browser.page_source
soup = BeautifulSoup(html, "lxml")

print(len(soup.find_all("table")))
print(soup.find("table", {"id": "expanded_standings"}))

browser.close()
browser.quit()
请参见
selenium


如果您在
Linux
上,并且得到错误
Chromedriver可执行文件需要位于路径中
,那么请尝试以下方法-,

其余的由JS加载。这是什么意思?您知道我如何访问它吗?您可以使用selenium访问其余部分。