Question one: Python 3.x or above includes URLLIB2, integrating URLLIB2 and Urllib.
and introduce the module into one, only import urllib
# import urllib# Import urllb2# Correct use of import urllib
So you cannot use the Urllib2.urlopen () method, or you will get an error without this module.
Nameerror:name ' URLLIB2 ' is not defined
3.x or above version # Urllib2.open not available, use Urllib.request module instead of URLLIB2
1 Import urllib.request 2 3 response = Urllib.request.urlopen (' http//www.baidu.com')
Problem Two: variable name cannot be the same as introducing module name method, otherwise it will cause an error
1 Importurllib.request2 3 #wrong wording4 5Request = Urllib.request.urlopen ('/HTTPwww.baidu.com')6 7 #otherwise TypeError: ' Module ' object is not callable8 9 #correct wordingTen OneRQS = Urllib.request.urlopen ('/HTTPwww.baidu.com')
Issue four print output issues
The 3.x version of print has become a method of outputting anything that needs to be included in () brackets, or there will be a problem
The first step of the initial approach to crawl Baidu home
1 Import urllib.request 2 3 RQS = Urllib.request.urlopen ('http://www.baidu.com')4 5 html = rqs.read ()67print(HTML)
python3.x above crawler use problem Urllib (cannot use URLLIB2)