首页 > 解决方案 > 为什么我在尝试从网站收集价格时收到非类型错误?

问题描述

这是我在 Jupyter-Lab 中的代码:

import requests
from bs4 import BeautifulSoup

secure = "https://"
city = input("Type name of city without spaces:")
url = ".craigslist.org/d/for-sale/search/sss?query="
instrument = input("Type name of instrument without spaces:")

for x in page:
    x = 0
    x = x + 1
page = "&s=" + str(120 * x)

z = secure + city + url + instrument + page
y = requests.get(url = y)
htmlread = z.content

bs = BeautifulSoup(htmlread, 'html.parser')

price = bs.findAll('span', 'result-price')
pl = []
for a in price:
    pricelist = a.span.string
    pl.append(pricelist)
print(pl)

这是我得到的错误:

AttributeError:“NoneType”对象没有属性“字符串”

标签: pythonjupyter-lab

解决方案


尝试使用a.text而不是a.span.string


推荐阅读