Я изучаю BeautifullSoup с кодом Visual Studio, и когда я запускаю этот скрипт:
import requests
from bs4 import BeautifulSoup
from fake_useragent import UserAgent
ua = UserAgent()
header = {'user-agent':ua.chrome}
google_page = requests.get('https://www.google.com',headers=header)
soup = BeautifulSoup(google_page.content,'lxml') # html.parser
print(soup.prettify())
И я получаю следующую ошибку:
Трассировка (последний последний вызов): Файл "c:\ ... \intro-to-soup-2.py", строка 13, в печати (soup.prettify()) Файл "C:\ ... \Local \Programs\Python\Python36-32\lib\encodings\cp1252.py", строка 19, в кодировке возврата codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: кодек 'charmap' не может кодировать символ '\U0001f440' в позиции 515: сопоставление символов с
Если я форсирую кодировку utf-8 в переменной супа, я не смогу использовать prettify, так как он не работает со строками... Также пытался использовать # -- coding: utf-8 - em>- в первой строке кода без успеха.
Вот мои tasks.json для этого проекта:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "python",
"isShellCommand": true,
"args": ["${file}"],
"files.encoding": "utf8",
// Controls after how many characters the editor will wrap to the next line. Setting this to 0 turns on viewport width wrapping (word wrapping). Setting this to -1 forces the editor to never wrap.
"editor.wrappingColumn": 0, // default value is 300
// Controls the font family.
"editor.fontFamily": "Consolas, 'Malgun Gothic', '맑은 고딕','Courier New', monospace",
// Controls the font size.
"editor.fontSize": 15,
"showOutput": "always"
}
Точно такой же код работает в PyCharm без проблем. Любые идеи, как я могу исправить это в коде Visual Studio?
Вот мой результат "заморозки пипсов":
astroid==1.5.3
beautifulsoup4==4.5.3
colorama==0.3.9
fake-useragent==0.1.7
html5lib==0.999999999
isort==4.2.15
lazy-object-proxy==1.3.1
lxml==3.7.2
mccabe==0.6.1
pylint==1.7.1
requests==2.12.5
selenium==3.4.3
six==1.10.0
webencodings==0.5
wrapt==1.10.10
xlrd==1.0.0
XlsxWriter==0.9.6
Спасибо за ваше время,
Юнито.
import sys; print('Python %s on %s' % (sys.version, sys.platform))
. Кроме того, pycharm может использовать любую имеющуюся у вас установку (если у вас несколько установок), поэтому его недавняя загрузка не гарантирует, что он запускает последнюю версию Python. - person TrakJohnson   schedule 23.06.2017