【发布时间】:2019-03-21 05:49:09
【问题描述】:
从代码中的 url,我最终试图从页面中收集所有玩家的名字。但是,当我使用 .findAll 来获取所有列表元素时,我还没有成功。请指教。
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
players_url = 'https://stats.nba.com/players/list/?Historic=Y'
# Opening up the Connection and grabbing the page
uClient = uReq(players_url)
page_html = uClient.read()
players_soup = soup(page_html, "html.parser")
# Taking all of the elements from the unordered lists that contains all of the players.
list_elements = players_soup.findAll('li', {'class': 'players-list__name'})
【问题讨论】:
-
找不到什么?
-
页面中生成的玩家列表是用javascript完成的。您需要一个可以完全呈现页面的客户端。通常一种常见的方法是驱动浏览器访问 url(您可以为此使用 selenium),获取页面源然后将其提供给漂亮的汤。
标签: python web-scraping beautifulsoup