百度爬虫问题
import requestsurl='http://www.baidu.com'
context=requests.get(url)
filename='百度爬虫.html'
file=open(filename,'w')
file.write(context.text)
file.close()
结果出现traceback
Traceback (most recent call last):
File "C:\Users\86177\Desktop\didi\编程\爬虫\text.py", line 6, in <module>
file.write(context.text)
UnicodeEncodeError: 'gbk' codec can't encode character '\xe7' in position 295: illegal multibyte sequence
[Finished in 670ms]
将‘w’改为‘wb’
会出现
typeError: a bytes-like object is required, not 'str
但这个代码把网址改为‘http://www.’又没错误
求大佬帮助