1.做网页爬虫的时候遇到的; python 3.x版本中可以import urllib.request,而python2.x版本没有request这个module,最后只能import urllib2。 request模块可以用作对网页的索取,如: ---------------------------------- python 2.x import urllib2 url = "http://www.sina.com" html = urllib2.Request(url) --------------------------------- python3.x import urllib.request url = "http://www.sina.com" html = urllib.Request(url) 2.print差异: python3.x版本print作为一个函数出现,所以在使用print时需要加上括号。 --------------------------------- python 2.x a = 'hello world!' print a --------------------------------- python 3.x a = 'hello world!' print(a) |
|
来自: 昵称16237642 > 《笔记》