免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2039 | 回复: 0
打印 上一主题 下一主题

提示没有属性。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-11-07 13:11 |只看该作者 |倒序浏览
下面的代码运行时为什么提示:AttributeError: 'module' object has no attribute 'detect'
实际上是不缺少的。谁来解释下,谢谢。
  1. #coding:gbk

  2. import sys
  3. import urllib2
  4. import chardet

  5. def blog_detect(blogurl):
  6.     try:
  7.         fp = urllib2.urlopen(blogurl)
  8.     except Exception,e:
  9.         print e
  10.         print 'download exception %s' % blogurl
  11.         return 0
  12.     blog = fp.read()
  13.     codedetect = chardet.detect(blog)["encoding"]
  14.     print '%s\t<-\t%s' % (blogurl,codedetect)
  15.     fp.close()
  16.     return 1

  17. if __name__ == "__main__":
  18.     if len(sys.argv) == 1:
  19.         print 'usage:\n\tpython cdays-1-exercise-1.py http://xxxx.com'
  20.     else:
  21.         blog_detect(sys.argv[1])
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP