【发布时间】:2017-02-28 02:56:52
【问题描述】:
我是 python 初学者。我写的代码如下:
from bs4 import BeautifulSoup
import requests
url = "http://www.google.com"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
links = soup.find_all("a")
for link in links:
print(link.text)
在 windows powershell 中运行这个 .py 文件时, print(link.text) 会导致以下错误。
error: UnicodeEncodeError: 'gbk' codec can't encode charactor '\xbb' in position 5:
illegal multibyte sequence.
我知道这个错误是由一些汉字引起的,而且我似乎应该使用“解码”或“忽略”,但我不知道如何修复我的代码。请帮忙!谢谢!
【问题讨论】:
标签: python