爬文本虫。出现问题:'utf-8' codec can't decode byte 0xb5 in position 105: invalid start byte

'utf-8' codec can't decode byte 0xb5 in position 105: invalid start byte

“utf-8”编解码器无法解码位置105中的字节0xb5:起始字节无效

解决方法:

查看网页源代码,charset=gbk还是charset=utf-8。发现https://www.biqukan.com/1_1094/5403177.html网页它是
第一章 他叫白小纯_一念永恒_修真小说_笔趣阁

那么我将utf-8改成gbk即可

# -*- coding:UTF-8 -*-
import requests

if __name__ == '__main__':
    target = 'https://www.biqukan.com/1_1094/5403177.html'
    req = requests.get(url=target)
    req.encoding = 'gbk'
    print(req.text)

 

就可以了

你可能感兴趣的:(新学python)