AttributeError:' NoneType'对象没有属性'编码'

时间:2014-03-18 18:17:11

标签: python beautifulsoup

我正在使用Python获取网址并修改它们。 这是发生此错误的地方:

for link in soup.findAll('a'):
    linkori = (link.get('href'))
    print 'LINKORI : %s' %linkori
    fonte1 = linkori
    fonte1 = str(fonte1.encode('utf8'))

我的追溯:

  File "C:\Python27\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
    exec codeObject in __main__.__dict__
  File "F:\Docs\Projti\Rafael\Python Scripts\final.py", line 258, in <module>
    fonte1 = str(fonte1.encode('utf8'))
AttributeError: 'NoneType' object has no attribute 'encode'

我尝试了.join或其他东西,但我总是得到同样的错误。当我打印linkori时,它会完美显示link.get的网址。 有人能告诉我出了什么问题吗?

0 个答案:

没有答案
相关问题