python-3.x - “utf-8”编解码器无法解码字节 0xd7:无效的继续字节
问题描述
注意:此测试作为目标站点错误赏金计划的一部分运行。
我正在尝试使用requests
in解析从 Google 返回的结果Python3
。
我遇到的问题是我收到以下错误:
'utf-8' codec can't decode byte 0xd7 in position 5698: invalid continuation byte
这是相关代码:
def __init__(self):
self.soup = BeautifulSoup(features="html.parser")
self.query_addr = "http://www.google.com/search?"
def parse_search_results(self, res):
links = []
soup = self.soup(res) # This call triggers the error
no_results = soup.find("did not match any documents.")
截屏:
我将res
(这是一个字节对象)的结果保存在一个 html 文件中并在浏览器中查看它。您可以看到呈现的违规字节。
这是res
没有封闭的价值b''
,我已经把它放在了Github上。
我也没有decode
在我的代码中的任何地方显式调用或指定utf-8
. 我的理解是它BeautifulSoup
自己处理。
我需要做什么才能BeautifulSoup
正确解析这些数据?
解决方案
推荐阅读
- c - 交换链表中的某些元素
- javascript - 从 html 表中追加数据而不是另存为新文件
- python - 如何修复 tkinter 中的“'int' object is not iterable”错误
- ios - CLI 命令未上传 dSYM
- php - 如何用 php 打印这些 json 值
- javascript - Jest 中的 resetAllMocks、resetModules、resetModuleRegistry、restoreAllMocks 之间的区别
- python - 我正在尝试获取我打印的内容并将其添加到列表中以作为员工工资单打印出来
- html - 将谷歌表格中的一周时间表整合到 webnode 网站中
- python - 在散景图的轴上突出显示许多范围?
- reactjs - 令牌认证返回 403 (Axios + Django Rest Framework)