- 论坛徽章:
- 0
|
下面的代码运行时为什么提示:AttributeError: 'module' object has no attribute 'detect'
实际上是不缺少的。谁来解释下,谢谢。- #coding:gbk
- import sys
- import urllib2
- import chardet
- def blog_detect(blogurl):
- try:
- fp = urllib2.urlopen(blogurl)
- except Exception,e:
- print e
- print 'download exception %s' % blogurl
- return 0
- blog = fp.read()
- codedetect = chardet.detect(blog)["encoding"]
- print '%s\t<-\t%s' % (blogurl,codedetect)
- fp.close()
- return 1
- if __name__ == "__main__":
- if len(sys.argv) == 1:
- print 'usage:\n\tpython cdays-1-exercise-1.py http://xxxx.com'
- else:
- blog_detect(sys.argv[1])
复制代码 |
|