Traceback (most recent call last):
File "C:/Users/Lenovo/PycharmProjects/untitled3/text6.py", line 49, in <module>
printGoodsList(infoList)
序号 价格 商品名称
File "C:/Users/Lenovo/PycharmProjects/untitled3/text6.py", line 34, in printGoodsList
print(tplt.format(count, g[0], g[1]))
1 199.00 <em>斯多朴<font class="skcolor_ljg">aj</font>空军一号高帮鞋篮球鞋蜘蛛侠球鞋6欧0文小闪电哈登5联名男鞋 988-黑白红 42-标准运动码</em>
TypeError: unsupported format string passed to NoneType.__format__
分析
爬虫在提取信息时有时候会提取到空标签,而返回NoneType类。什么是NoneType类呢?简单说就是其值为None的类。而print不能打印None,所以需要过滤一遍提取的信息,把NoneType类型给去掉。
.解决办法
for g in ilt:
if g[1] is not None and g[0] is not None:
count = count + 1
print(tplt.format(count, g[0], g[1]))