为什么我在尝试从网站收集价格时会收到非类型错误?
Why am I getting a nonetype error when trying to collect prices from a website?
这是我在 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' 对象没有属性 'string'
尝试使用 a.text
而不是 a.span.string
这是我在 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' 对象没有属性 'string'
尝试使用 a.text
而不是 a.span.string