python - Python:网站的类打印出一个空列表
问题描述
我正在尝试使用以下脚本抓取类stats
(item price
和) 中的所有内容:price changes
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
url = "https://secure.runescape.com/m=itemdb_oldschool/Dragon+warhammer/viewitem?obj=13576"
uClient = uReq(url)
page_html = uClient.read()
page_soup = soup(page_html, "html.parser")
price = page_soup.find_all(class_ = "stats")
print(price)
我得到这个打印:
[]
我将这个脚本用于我所有的其他 webscrappes,这是我第一次得到这样的东西。
我试着环顾四周,问了一些人,我仍然找不到解决方案。
解决方案
检查page_soup变量的值:
<html style="height:100%"><head><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"><meta name="format-detection" content="telephone=no"><meta name="viewport" content="initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><script type="text/javascript" src="/_Incapsula_Resource?SWJIYLWA=719d34d31c8e3a6e6fffd425f7e032f3"></script><script src="/Criciousand-meth-shake-Exit-be-till-in-ches-Shad" async></script></head><body style="margin:0px;height:100%"><iframe id="main-iframe" src="/_Incapsula_Resource?SWUDNSAI=30&xinfo=7-5532445-0%20NNNY%20RT%281620414344651%2056%29%20q%280%20-1%20-1%201%29%20r%281%20-1%29%20B12%2814%2c0%2c0%29%20U5&incident_id=1233000410021120939-28775082668132935&edet=12&cinfo=0e000000d694&rpinfo=0&cts=UC3pkO3NyZP9f4EA4%2fm56lwz1Y6BhOV6CwF4xNVSeeeNp96DzLjUUDt3%2b5RYEDst" frameborder=0 width="100%" height="100%" marginheight="0px" marginwidth="0px">Request unsuccessful. Incapsula incident ID: 1233000410021120939-28775082668132935</iframe></body></html>
如果您以隐身模式访问该网站,您将看到相同的结果。
由于该页面没有名为 'stats' 的类,因此page_soup.find_all(class_ = "stats")的结果是一个空列表。
推荐阅读
- cakephp - 数组控制器 cakephp 上的分页
- excel - 在公式中查找和替换文件名并重新计算公式
- javascript - 在 React 应用程序中渲染外部网页
- python - 使用 functools lru_cache,如何确定函数是否返回了缓存数据?
- typescript - 在 PhpStorm 项目中使用带有 Typescript 的 window.openDatabase
- kendo-ui - Kendo UI Grid ServerBound ClientTemplate 替代条件语句
- sql - 使用条件选择结果与另一个表连接
- javascript - 如何修改 ES6 类的构造函数
- json - 如何使用 Python 解析 Spark 1.6 中包含空格、额外双引号和反斜杠的格式不正确的 JSON 字符串?
- python - 如何在 tkinter 中等待多次按键?