0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VSCodeターミナルでPythonの文字化けが発生する

0
Posted at

この記事は過去のエラー解決メモを整理したものです。
現在の推奨手順とは異なる可能性があります。
公式ドキュメントを確認して最新情報と差分がないかを確認してください。

事象

VSCodeのターミナル(cmd)でPythonを実行したところ、日本語が文字化けした。

>>> import random
>>> from bs4 import BeautifulSoup
>>> url = "https://buyerz.shop/shopbrand/ct434/"
>>> res = requests.get(url)
>>> soup = BeautifulSoup(res.content,"html.parser")
>>> sleep(random.randint(1,2))
>>> h1_tag = soup.find("h1")
>>> print(h1_tag)
<h1>»ÅÆþ¤ì²·Ìä²°¤È¥É¥í¥Ã¥×¥·¥Ã¥Ô¥ó¥°¤Î¥Ð¥¤¥ä¡¼¥º</h1>
>>>

環境

  • Windows 10
  • Python 3.9系
  • VSCode 1.61.2
  • VSCodeターミナル(cmd)

原因

文字コードまたはターミナル環境の影響と考えられるが、明確な原因は未確認。

対策

  • cmdではなくPowerShellで python foo.py を実行する。
  • VSCodeのデバッグ実行(F5)で実行する。

参考情報

未記載

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?