【发布时间】:2019-07-16 17:52:57
【问题描述】:
我正在通过 NBA 网站获取球员姓名。玩家姓名网页是使用单页应用程序设计的。播放器按字母顺序分布在多个页面中。我无法提取所有玩家的名字。 这是链接:https://in.global.nba.com/playerindex/
from selenium import webdriver
from bs4 import BeautifulSoup
class make():
def __init__(self):
self.first=""
self.last=""
driver= webdriver.PhantomJS(executable_path=r'E:\Downloads\Compressed\phantomjs-2.1.1-windows\bin\phantomjs.exe')
driver.get('https://in.global.nba.com/playerindex/')
html_doc = driver.page_source
soup = BeautifulSoup(html_doc,'lxml')
names = []
layer = soup.find_all("a",class_="player-name ng-isolate-scope")
for a in layer:
span = a.find("span",class_="ng-binding")
thing = make()
thing.first = span.text
spans = a.find("span",class_="ng-binding").find_next_sibling()
thing.last = spans.text
names.append(thing)
【问题讨论】:
标签: python web-scraping beautifulsoup