一开始使用了beautifulSoup的get_text()进行字符串的提取,后来一直提取失败,并提示错误为TypeError: 'NoneType' object is not callable

返回了none类型,可能是对Span标签内容的提取产生错误,于是采用name.string进行字符的提取,成功。

# -*- coding: utf-8 -*-
"""
Created on Wed Jan 11 17:21:54 2017

@author: PE-Monitor
"""
import urllib2
import BeautifulSoup
import sys

reload(sys)
sys.setdefaultencoding('utf-8')
responce = urllib2.urlopen("http://www.pythonscraping.com/pages/warandpeace.html")
html =BeautifulSoup.BeautifulSoup(responce)
nameList=html.findAll('span',{'class':{'green'}})
for name in nameList:
     print(name.string)
    
    

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
  • 2021-11-14
  • 2022-01-10
  • 2022-12-23
  • 2021-06-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2021-08-26
  • 2022-12-23
相关资源
相似解决方案