首页 > 解决方案 > BeautifulSoup.find() is returning None, unable to access table on wiki page

问题描述

import requests
from bs4 import BeautifulSoup


url = "http://leagueoflegends.wikia.com/wiki/List_of_items'_stats"
page = requests.get(url).text

pageSoup = BeautifulSoup(page, 'html5lib')

table = pageSoup.find('table',{'class':'wikitable sortable'})
print(table)

I am trying to access the data from a table on a wiki page. I have already accessed the table on another page, however the return I am getting from the find function from this page is None. Also, when i print all p tags, there is only one p tag in the whole of the soup, which seems strange to say the least, therefore I think there might be an error in the way I am accessing the html. Any help would be appreciated.

标签: python-3.xbeautifulsouppython-requests

解决方案


问题是后台有一个动态选项卡机制。您应该选择所需的选项卡并使用链接。例如,如果您想查看“进攻”选项卡,可以右键单击并打开相应的页面,这将为您提供正确的 url,然后您的代码将正确运行:

url = 'http://leagueoflegends.wikia.com/wiki/List_of_items%27_stats/Offensive'

推荐阅读