笔记
1.AJAX
AJAX是异步javascript与XML。在不刷新网页的情况下更新网页数据。
2.JSON
JSON是一种格式化字符串。JSON是一种轻量级的数据交换格式。
2.1 字典=>json
json.dumps()
2.2 json =>字典
json.loads()
3.普通异步加载获取
谷歌浏览器右键——检查——network
3.1 get ajax获取
import requests
html=requests.get("http://exercise.kingname.info/ajax_1_backend").content.decode()
print (html)
3.2 post ajax 获取
import requests
html=requests.post("http://exercise.kingname.info/ajax_1_postbackend",json={'name':'dudu','age':18}).content.decode()
print (html)
4. 特殊的异步ajax
使用javascrip对数据进行加载。
抓取内容:
import requests
import re
import json
html=requests.get("http://exercise.kingname.info/exercise_ajax_2.html").content.decode()
code=re.search("secret = '(.*?)'",html,re.S).group(1)
# print (code)
cpde_dict=json.loads(code)
print (cpde_dict['code'])
5. 多次请求的异步加载
使用多次requests去请求,然后分析即可。
6.基于异步加载的简单登录
使用post来进行请求,一般情况下使用json来进行传参。