这是我在 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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句