Python 2.7 Soup.find和findAll在hockey-reference.com上找不到表元素

Python 2.7 Soup.find和findAll在hockey-reference.com上找不到表元素,python-2.7,web-scraping,beautifulsoup,Python 2.7,Web Scraping,Beautifulsoup,我只是一个webscraping和python的初学者,所以如果答案很明显,我很抱歉,但是我不知道我在上面找不到任何表元素 我最初的想法是,这是整个div被注释掉的结果,因此根据我在另一篇类似文章中找到的一些建议,我替换了注释字符,并确认在我将soup.text保存到文本文件并进行搜索时,它们已被删除。然而,我仍然找不到任何表格 在尝试进一步搜索的过程中,我从我的.find中取出了ID,并进行了一次findAll,结果仍然是空的 这是我试图使用的代码,任何建议都非常感谢 import csv i

我只是一个webscraping和python的初学者,所以如果答案很明显,我很抱歉,但是我不知道我在上面找不到任何表元素

我最初的想法是,这是整个div被注释掉的结果,因此根据我在另一篇类似文章中找到的一些建议,我替换了注释字符,并确认在我将soup.text保存到文本文件并进行搜索时,它们已被删除。然而,我仍然找不到任何表格

在尝试进一步搜索的过程中,我从我的.find中取出了ID,并进行了一次findAll,结果仍然是空的

这是我试图使用的代码,任何建议都非常感谢

import csv
import requests
from BeautifulSoup import BeautifulSoup
import re

comm = re.compile("<!--|-->")

url = 'https://www.hockey-reference.com/leagues/NHL_2018.html'
response = requests.get(url)
html = response.content

soup = BeautifulSoup(comm.sub("", html))
table = soup.find('table', id="stats")

我也知道网站上有一个csv版本,我只是急于练习。

在标记的同时提供一个解析器,例如
BeautifulSoup(html,'lxml')
。请尝试下面的代码

url = 'https://www.hockey-reference.com/leagues/NHL_2018.html'
response = requests.get(url)
html = response.content
soup = BeautifulSoup(html,'lxml')
table = soup.findAll('table')
url = 'https://www.hockey-reference.com/leagues/NHL_2018.html'
response = requests.get(url)
html = response.content
soup = BeautifulSoup(html,'lxml')
table = soup.findAll('table')