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

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

import urllib.request

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

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

错误提示1:

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

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

错误提示2 :

No module named 'urllib2'

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

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



你可能感兴趣的:(Python 3.4 - urllib.request 学习爬虫爬网页(一))