1.报错“UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte“
解决:
把:result = html.read().decode('utf-8') #这句话有编码问题
改为:
result = html.read()
result = result.decode('utf-8')
result
2.报错“ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。”
解决:在后面要有close()操作
因为在前面有urlopen()操作后没有close()操作,容易被认为是攻击行为,连接失败。
3.爬虫时,如果需要输入url的headers,需要用字典形式。