当前位置:网站首页>爬虫小操作
爬虫小操作
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))
边栏推荐
- RESTful风格
- QT signal and slot communication mechanism (when multiple windows communicate back and forth [parent and child windows])
- Comprehensive evaluation of outline note taking software workflow: advantages, disadvantages and evaluation
- PMP考试重点总结五——执行过程组
- Looking at jBPM from jbm3 to jbm5 and activiti
- 1181: integer parity sort
- Thread lifecycle
- Inventory of excellent note taking software: good-looking and powerful visual note taking software, knowledge map tools heptabase, hydrogen map, walling, reflect, infranodus, tiddlywiki
- 异常处理4种方法
- 剑指Offer | 链表转置
猜你喜欢

bye! IE browser, this route edge continues to go on for IE

Dolphin scheduler uses system time

Decorator

Installing redis under Linux and windows (ultra detailed graphic tutorial)

Interpretation of new products: realm launched GT neo2 Dragon Ball customized version

Dbeaver connects to kingbasees V8 (ultra detailed graphic tutorial)

小米旗下支付公司被罚 12 万,涉违规开立支付账户等:雷军为法定代表人,产品包括 MIUI 钱包 App

Thread lifecycle

虚拟机14安装win7(图教程)

new URL(“www.jjj.com“)
随机推荐
DolphinScheduler使用系统时间
创建多线程的方法---1创建Thread类的子类及多线程原理
PMP examination key summary VIII - monitoring process group (2)
Key summary IV of PMP examination - planning process group (2)
Two interview demo
Check whether the table contains rows SQL Server 2005 - check whether a table contains rows or not SQL Server 2005
卸载oracle报错
Machine virtuelle 14 installer win7 (tutoriel)
大纲笔记软件 Workflowy 综合评测:优点、缺点和评价
Function sub file writing
再见!IE浏览器,这条路由Edge替IE继续走下去
Comprehensive evaluation of outline note taking software workflow: advantages, disadvantages and evaluation
Dbeaver连接人大金仓KingbaseES V8(超详细图文教程)
PMP考试重点总结五——执行过程组
How to view the web password saved by Google browser
JSON数据与List集合之间的正确转换
1182: effets de la photo de groupe
全链路业务追踪落地实践方案
Redis sentinel cluster main database failure data recovery ideas # yyds dry goods inventory #
JVM family (2) - garbage collection