python - 为什么我在尝试从网站收集价格时收到非类型错误?
问题描述
这是我在 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”对象没有属性“字符串”
解决方案
尝试使用a.text
而不是a.span.string
推荐阅读
- c# - 将文本转换为 C# 数组
- java - 由于不存在 jstack 和 jmap,如何使用 java 1.8 进行线程转储
- python - 合并两个不同长度的数据帧
- jwt - Angular 6 - 将 JWT 不记名令牌添加到标头不起作用
- asp.net-web-api - WebAPI 在 PUT/DELETE 操作上返回 404
- elasticsearch - ELK 堆栈数据映射功能
- c - 找到一个数字的 2s 补码的最快方法是获取最右边的设置位并将所有内容翻转到它的左侧
- spring - Kotlin (Spring boot) - 创建带有名称的 bean 时出错
- c - win32-pthreads 未定义的 sem_init 行为
- javascript - 画布到图像有效,但不适用于 canvas.drawImage