RT,猜测需要先解码然后编码,但测试了一下一直报错,求解。
命令行:下载某网站上指定关键词的图书的信息
python downloadBook.py -n 红楼梦
报错信息:
UnicodeDecodeError: 'utf8' codec can't decode byte 0xbb in position 0: invalid start byte
代码,错误发生在第3行:
if __name__ == "__main__": if sys.argv[1] == "-n": bookname = sys.argv[2] bookUrls = collectUrls(bookname) for i in range(len(bookUrls)): book = downloadBook(i, bookUrls[i])
很簡單,utf8沒辦法解碼,可以試試gbk,gb2312