Wu Yuxiong --python study notes: Replace reptiles package

python 3.x given: No Module1 the named ' cookielib ' or the named Module1 No ' urllib2 '
ModuleNotFoundError 1.: No Module1 the named ' cookielib ' 
Python3 in, Import   cookielib into Import   The http.cookiejar, and the method was also changed cookielib http.cookiejar.

2.    ModuleNotFoundError: No module named 'urllib2'

Urllib2 in Python 3 was replaced with urllib.request.

It has been explained in the official Python documentation inside:

Note:

The urllib2 module has been split across several modules in Python 3.0 named urllib.request and urllib.error. The 2to3 tool will automatically adapt imports when converting your sources to 3.0.

from urllib.request import urlopen

response = urlopen("http://www.google.com")

html = response.read()

print(html)

3.    NameError: name 'raw_input' is not defined

Python 3 with input () Replace the raw_input ()

4.    UserWarning: You provided Unicode markup but also provided a value for from_encoding. Your from_encoding will be ignored.

Note the phrase: warnings.warn ( " by You Provided Provided Unicode Markup But Also A value for from_encoding Your from_encoding by Will BE ignored.. " ) The reason: python3 default encoding is the unicode, and then set to utf8 in from_encoding, will be ignored.

In Python 3 Soup = the BeautifulSoup (html_doc, " html.parser " , = from_encoding " UTF-. 8 " ) The sentence deleted = from_encoding " UTF-. 8 "

 

Guess you like

Origin www.cnblogs.com/tszr/p/11960003.html