python-3.x - 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.
解决方案
问题是后台有一个动态选项卡机制。您应该选择所需的选项卡并使用链接。例如,如果您想查看“进攻”选项卡,可以右键单击并打开相应的页面,这将为您提供正确的 url,然后您的代码将正确运行:
url = 'http://leagueoflegends.wikia.com/wiki/List_of_items%27_stats/Offensive'
推荐阅读
- .htaccess - 指定并测试 htaccess HTTP_ACCEPT
- vue.js - 属性或方法“$v”未使用 Vuelidate 定义
- neo4j - 如何将两个节点合并在一起并保留到 NEO4j / Cypher 中节点的所有链接?
- ibm-watson - IBM Watson Assistant:我如何让聊天机器人重复响应,直到它识别出用户在说什么?
- r - 从其他 data.table 添加列的更好语法
- bootstrap-4 - 如何在 Angular 6 项目上从引导程序 3.3.7 正确升级到 4.0
- c# - 从自定义脚本 (UNITY) 在 c# 中使用 maths.lerp
- typescript - 未捕获的错误:无法解析 ProductListComponent 的所有参数?
- bash - Grep 排除注释,如 # 和 -- 带有尾随空格和行内
- python-3.x - 有没有办法编辑**的行为