当前位置:网站首页>Crawler small operation
Crawler small operation
2022-07-26 00:47:00 【Pert-】
take reponse The content is displayed in Chinese , And then str To dict
res=response.content.decode("unicode_escape")
res_dict=json.loads(res)
obtain token( Look yes localStorage still SessionStorage), need sleep Wait for a while token Pass it on to get
token = self.driver.execute_script('return localStorage.getItem("token");')
print('\ntoken by :%s\n'%token)
obtain cookie
# obtain cookie
cookie_tag = self.driver.get_cookies()
# print(cookie_tag)
# Handle cookie In the format you need
cookie = cookie_tag[0]['name'] + '=' + cookie_tag[0]['value']
print('\ncookie by :%s\n'%cookie)
Read 、 Write file garbled
### Read
f=open('{}'.format(file_catalogue+'/'+file_list[0]),mode='r',encoding='utf-8',errors='ignore')
contentJson=json.load(f)
print(contentJson)
### write in
with open('student.json',mode='w',encoding='utf8') as f:
json.dump(jsonA,f,ensure_ascii=False,index=2) #ensure_ascii=False Don't let Chinese characters turn into ASCII
#f.write(jsonA) # It is not allowed to write... In the form of ordinary file Because the suffix is json
Make the dictionary easier to view
print(json.dumps(dict_data,indent=1,ensure_ascii=False))
Turn the data you climb down into python type
json.loads(str(response.text),strict=False)
边栏推荐
- 攻防世界web题-favorit_number
- Analysis and practice of parameter parser handlermethodargumentresolver
- With data-driven management transformation, the first year of science and technology was at the right time
- sql(基础二)
- [array related methods in numpy]
- OAuth2和JWT
- 【NumPy中数组相关方法】
- 2022/7/24 考试总结
- 力扣记录:剑指offer(2)——JZ13-22
- [oops framework] interface management
猜你喜欢
随机推荐
HCIA comprehensive experiment
Seretod2022 track1 code analysis - task-based dialogue system challenge for semi supervised and reinforcement learning
开放下载!《阿里巴巴 DevOps 实践手册》
【RTOS训练营】上节回顾、空闲任务、定时器任务、执行顺序、调度策略和晚课提问
Jmeter之用户自定义变量和抽离公共变量
[array creation in numpy]
南姐的糗事
JDBC实现MySQL8.0数据库的增删改查
Analysis and practice of parameter parser handlermethodargumentresolver
Database tools duel: heidisql and Navicat
Distributed transaction and at mode principle of Seata
[oops framework] random number generation management
聊聊研发团队中的“人”
[GOM engine] script setting method for dummy configuration
使用LocalDate类完成日历设计
Leetcode notes 121. the best time to buy and sell stocks
Research on visualization method of technology topic map based on clustering information
用 QuestPDF操作生成PDF更快更高效!
Solve the problem that when the background image is set to be 100% full, when the horizontal scroll bar appears in the zoom browser, the part of the background image beyond the scroll bar is not full
测试左移和测试右移的概念









