justcode.ikeepstudying.com
python 3.5: a bytes-like object is required,not 'str' 报错 - Just Code
今天用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了。 更多参考: python:字符串string 开头r,b,u,f 含义, str bytes 转换 […]
Gideon