2
我正试图放在一起的网络刮板,并遇到了这个错误,我不知道如何修改,我看错误与同名,但没有看到与我的相似之处..我很新的这个顺便说一句。使用字符串/文本,TypeError:'NoneType'对象不可调用
的代码如下,
import bs4 as bs
from urllib import urlopen as uReq
sauce = uReq('http://servicios.lanacion.com.ar/archivo-f11/02/2017-c30')
soup = bs.BeautifulSoup(sauce,'html.parser')
acumulados = soup.findAll('li',{'class':'acumulados'})
filename = 'LaNacion.csv'
f = open(filename,'w')
headers = "Título, Encabezado\n"
f.write(headers)
for acum in acumulados:
title = acumulados[0].a
encabezado = acumulados[0].p
f.write(title.replace(',',' ') + ',' + encabezado.replace(',',' ') + '\n')
f.close()
谢谢!
是的!谢谢,所以我正在学习的是,随着'你变成了一个对象'的方法,对吧?再次感谢 –
是的,'str'(它调用一个类的'__str __(self)'方法)返回一个字符串对象。那些有'替换'方法。 –