当前位置:网站首页>爬虫小操作
爬虫小操作
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))
边栏推荐
- DolphinScheduler使用系统时间
- PMP examination key summary VIII - monitoring process group (2)
- PMP考试重点总结五——执行过程组
- 用 Compose 实现个空调,为你的夏日带去清凉
- HDI的盲孔设计,你注意到这个细节了吗?
- new URL(“www.jjj.com“)
- Xiaomi's payment company was fined 120000 yuan, involving the illegal opening of payment accounts, etc.: Lei Jun is the legal representative, and the products include MIUI wallet app
- Multithreading concurrent parallel threaded process
- Bron filter Course Research Report
- Divide and rule classic Hanoi
猜你喜欢

再见!IE浏览器,这条路由Edge替IE继续走下去

卸载oracle报错

P2394 yyy loves Chemistry I

用 Compose 实现个空调,为你的夏日带去清凉

1181:整数奇偶排序

Au revoir! Navigateur ie, cette route Edge continue pour IE

Application of X6 in data stack index management
![[happy Lantern Festival] guessing lantern riddles eating lantern festival full of vitality ~ (with lantern riddle guessing games)](/img/04/454bede0944f56ba69cddf6b237392.jpg)
[happy Lantern Festival] guessing lantern riddles eating lantern festival full of vitality ~ (with lantern riddle guessing games)

How to reduce the risk of project communication?

new URL(“www.jjj.com“)
随机推荐
全局异常处理器与统一返回结果
栈的弹出压入序列<难度系数>
Machine virtuelle 14 installer win7 (tutoriel)
JDBC connection database (MySQL) steps
卸载oracle报错
HDI的盲孔设计,你注意到这个细节了吗?
大纲笔记软件 Workflowy 综合评测:优点、缺点和评价
Bron filter Course Research Report
【云驻共创】DWS告警服务DMS详细介绍和集群连接方式简介
PMP Exam key summary VI - chart arrangement
Summary of PMP learning experience
自定义异常类及练习
PMP考试重点总结六——图表整理
谁知道在中信建投证券开户是不是安全的
bad zipfile offset (local header sig)
The digital human industry is about to break out. What is the market pattern?
Matplotlib属性及注解
MySQL的开发环境和测试环境有什么区别??
Dbeaver连接人大金仓KingbaseES V8(超详细图文教程)
01-分布式系统概述