今天用python3的request写爬虫的时候遇到这个问题
查了很多,都没用,最后找到自己的解决办法
因为python3是bytes-like的,所以我们需要用split的话只能把它转为str
# bytes object
b = b"example"
# str object
s = "example"
# str to bytes
bytes(s, encoding = "utf8")
# bytes to str
str(b, encoding = "utf-8")
# an alternative method
# str to bytes
str.encode(s)
# bytes to str
bytes.decode(b)
这样就可以顺利使用split了。
————————点滴记录————————————

本文介绍了解决Python3爬虫中遇到的问题——如何将Bytes类型的对象转换为Str类型以便使用split方法。文章提供了具体的转换示例,帮助读者理解和应用。
330

被折叠的 条评论
为什么被折叠?



