Python:网站的类打印出一个空列表

问题描述

我正在尝试使用以下脚本抓取“统计”类(商品价格和价格变化)中的所有内容

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") 的结果是一个空列表。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...