Difference between Notepad2 and PyCharm - Stack Overflow
phpcn_u1582
phpcn_u1582 2017-05-18 10:50:11
0
1
759

The same code cannot pass in the Notepad environment (tested with Notepad), but can pass in Pycharm (Python3.5)
Code :

import urllib
import urllib.request
url = "http://www.baidu.com"
data = urllib.request.urlopen(url).read()
data = data.decode('UTF-8')

This statement can be passed in both environments

data.decode('gbk', 'ignore').encode('UTF-8')
print(data)

Display the crawled web page in Pycharm and display it in the cmd window

UnicodeEncodeError: 'gbk' codec can't encode character 'xbb' in position 26830:
illegal multibyte sequence

Invalid characters must be removed.

import urllib
import urllib.request
url = "http://www.baidu.com"
data = urllib.request.urlopen(url).read()
data.decode('gbk', 'ignore').encode('UTF-8')
print(data)

This is okay, please explain

phpcn_u1582
phpcn_u1582

reply all(1)
淡淡烟草味

You may encounter the same python encoding problem as me, or the encoding support problem of the terminal you are using. Take a look at the questions below.

【Python coding problem? 】Shared from @SegmentFault, portal: /q/10...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!