当前位置:网站首页>爬虫小操作
爬虫小操作
2022-06-28 09:39:00 【Pert-】
将reponse内容显示为中文,再将其str转为dict
res=response.content.decode("unicode_escape")
res_dict=json.loads(res)
获取token(看是localStorage还是SessionStorage),需要sleep一会等待token传过来才可以获取到
token = self.driver.execute_script('return localStorage.getItem("token");')
print('\ntoken为:%s\n'%token)
获取cookie
#获取cookie
cookie_tag = self.driver.get_cookies()
# print(cookie_tag)
#处理cookie成需要的格式
cookie = cookie_tag[0]['name'] + '=' + cookie_tag[0]['value']
print('\ncookie为:%s\n'%cookie)
读取、写入文件乱码
###读取
f=open('{}'.format(file_catalogue+'/'+file_list[0]),mode='r',encoding='utf-8',errors='ignore')
contentJson=json.load(f)
print(contentJson)
###写入
with open('student.json',mode='w',encoding='utf8') as f:
json.dump(jsonA,f,ensure_ascii=False,index=2) #ensure_ascii=False不让汉字转为ASCII
#f.write(jsonA) #不允许用普通文件的方式写入 因为后缀是json
将字典更方便查看
print(json.dumps(dict_data,indent=1,ensure_ascii=False))
边栏推荐
猜你喜欢

布隆过滤器 课程研究报告
![[ybtoj advanced training guide] maximum separation [hash] [Floyd]](/img/86/542ab1728a2ddbc01592b2fa83491a.jpg)
[ybtoj advanced training guide] maximum separation [hash] [Floyd]

mysql打不开,闪退

PyGame game: "Changsha version" millionaire started, dare you ask? (multiple game source codes attached)

Key summary V of PMP examination - execution process group

PMP考试重点总结五——执行过程组

Static page of pinyougou mall

Huawei OSPF single region

new URL(“www.jjj.com“)
![QT signal and slot communication mechanism (when multiple windows communicate back and forth [parent and child windows])](/img/17/57ffb7393b71eddc5ac92ae3944338.jpg)
QT signal and slot communication mechanism (when multiple windows communicate back and forth [parent and child windows])
随机推荐
Installing redis under Linux and windows (ultra detailed graphic tutorial)
PMP考试重点总结五——执行过程组
How to view the web password saved by Google browser
Au revoir! Navigateur ie, cette route Edge continue pour IE
线程和进程
【云驻共创】DWS告警服务DMS详细介绍和集群连接方式简介
Edit the live broadcast source code with me. How to write the live broadcast app code
Dolphin scheduler uses system time
Static page of pinyougou mall
Dbeaver连接人大金仓KingbaseES V8(超详细图文教程)
全局异常处理器与统一返回结果
Bridge mode
创建多线程的方法---1创建Thread类的子类及多线程原理
[ybtoj advanced training guidance] class roll call [string hash]
Machine virtuelle 14 installer win7 (tutoriel)
Matplotlib属性及注解
Sword finger offer | linked list transpose
2020-10-27
Data visualization makes correlation analysis easier to use
Naming rules and specifications for identifiers