|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import requests,bs4,re
- headers={'User-Agent':'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14'}
- res=requests.get('http://www.860816.com/aricle.asp?id=1785',headers=headers)
- with open('text.txt','w',encoding='utf-8') as name:
- name.write(res.text)
- sopu=bs4.BeautifulSoup(res.text,'html.parser')
复制代码
我打算保存各个城市的排名及数据,但是城市名称里是乱码,我以为是encoding='utf-8'的问题 ,改为encoding='gbk',报错。
https://blog.csdn.net/DCFANS/article/details/90199487
用了上面这个网站的方式,查了是gbk。
- import requests,bs4,re
- headers={'User-Agent':'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14'}
- res=requests.get('http://www.860816.com/aricle.asp?id=1785',headers=headers)
- res.encoding='gbk'
- with open('text.txt','w',encoding='utf-8') as name:
- name.write(res.text)
- sopu=bs4.BeautifulSoup(res.text,'html.parser')
复制代码
|
|