在运行下面的代码时显示报错'NoneType' object has no attribute 'find_all',请问该怎么解决
import requests
from bs4 import BeautifulSoup
# 发送HTTP请求并获取网页内容
url = 'http://pfsc.agri.cn/api/priceQuotationController/pageList?key=&order='
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"}
#"X-Requested-With": "XMLHttpRequest",
response = requests.get(url, headers=headers)
html_content = response.content
# 解析网页内容
soup = BeautifulSoup(html_content, 'html.parser')
# 提取农产品价格信息
product_prices = []
table = soup.find('table', class_='el-table__body')
rows = table.find_all('tr')
for row in rows:
cells = row.find_all('td')
if len(cells) == 3:
product_name = cells[0].text.strip()
product_price = cells[2].text.strip()
product_prices.append((product_name, product_price))
# 打印农产品价格信息
for product in product_prices:
print(product[0], product[1])
查一下soup.find函数的返回值是什么类型吧
table是none,或者row是none
仔细看报错信息,到底第几行报错,根据提示去查到底哪个变量有问题
找到出问题的变量,再继续往前找,看为什么find_all会找不到