首页 > 编程语言 > 详细

Python 3.4 - urllib.request 学习爬虫爬网页(一)

时间:2015-08-27 15:13:03      阅读:444      评论:0      收藏:0      [点我收藏+]

比如爬baidu.com,  在python 3.4 中应该这么写 

<span style="font-family:Microsoft YaHei;font-size:14px;">import urllib.request

def getHtml(url):
    page = urllib.request.urlopen(url)
    html = page.read()
    return html

html = getHtml("http://baidu.com")
print (html)
</span>

错误提示1:

print "hello" SyntaxError: Missing parentheses in call to ‘print‘

print 的语法在2 跟3 中不一样
print ("hello") in python 3
print "hello" in python 2

错误提示2 :

No module named ‘urllib2‘

python3.3里面,用urllib.request代替urllib2 

参考官方文档 https://docs.python.org/3/



版权声明:本文为博主原创文章,未经博主允许不得转载。

Python 3.4 - urllib.request 学习爬虫爬网页(一)

原文:http://blog.csdn.net/huxian370/article/details/48027711

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!