编写python爬虫脚本时,遇到“AttributeError"报错如何解决?


今天学习python语言爬虫知识时,遇到了困难,编译器总是报出“AttributeError",试了很多方法,还不能解决,求大神指导!!!

代码如下:


 # -*- coding: utf-8 -*-
import urllib

url = "http://www.baidu.com"

html = urllib.urlopen(url)
print html.read()

编译器结果截图:

图片描述

python2.7 python-爬虫 urllib

天雷劈着郭菊花 10 years, 3 months ago

可能在你的搜索路径中有另一个string.py,尝试


 import string
print string.__file__

看输出什么

高坂·桐乃 answered 10 years, 3 months ago

Your Answer