BS4 未在 Python 中定位元素

我对 Python 有点陌生,终生无法弄清楚为什么下面的代码没有拉出我想要获取的元素。


它目前返回:


for player in all_players:


    player_first, player_last = player.split()

    player_first = player_first.lower()

    player_last = player_last.lower()

    first_name_letters = player_first[:2]

    last_name_letters = player_last[:5]


    player_url_code = '/{}/{}{}01'.format(last_name_letters[0], last_name_letters, first_name_letters)

    player_url = 'https://www.basketball-reference.com/players' + player_url_code + '.html'

    print(player_url) #test

    req = urlopen(player_url)

    soup = bs.BeautifulSoup(req, 'lxml')

    wrapper = soup.find('div', id='all_advanced_pbp')

    table = wrapper.find('div', class_='table_outer_container')



    for td in table.find_all('td'):

        player_pbp_data.append(td.get_text())

目前返回:


--> for td in table.find_all('td'):

        player_pbp_data.append(td.get_text()) #if this works, would like to 


AttributeError: 'NoneType' object has no attribute 'find_all'

注意:遍历包装器对象的子对象返回:


< div class="table_outer_container" > 作为树的一部分。


侃侃无极
浏览 178回答 3
3回答

慕的地8271018

尝试显式传递 html:bs.BeautifulSoup(the_html,&nbsp;'html.parser')
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python