当前位置:网站首页>Dynamically load data
Dynamically load data
2022-07-29 07:59:00 【Zhao [email protected]】
| ajax request | json data |
|---|---|
| Dynamic loading , It will not be displayed in the web source code | json Is a data transmission format , It's essentially the object |
| Implement local update | Objects are used locally , and json It is used for data transmission |
take Python The object is encoded as JSON character string :
json.dumps(data)decode JSON object :
json.loads(jsonData)Will serialize str Save to file
json.dump(obj, fp,ensure_ascii=False)- obj: Represents the object to serialize . - fp: File descriptor , Will serialize str Save to file .json Module always generated str object , Not a byte object ; because this ,fp.write() Must support str Input . - ensure_ascii=Flase, No use ascii code , Press utf-8 codeRead from file json Format string , Turn into python object
json.load(fp)fp: File descriptor , take fp(.read() Support includes JSON Text or binary file of the document ) Deserialize to Python object .
Director of pharmaceutical Bureau
Page analysis :
- Determine whether the enterprise related data in the page is dynamically loaded ? Relevant enterprise information is dynamically loaded Through the packet capturing tool to achieve full Search for , Locate the data package corresponding to the dynamic loading data !
post:http://125.35.6.84:81/xk/itownet/portalAction.do?method=getXkzsList- The response data returned by the request is a set json strand , Through to json A simple analysis of string , No business details page found url, But find every enterprise id
- The details page of each enterprise url, The domain names are the same , The parameters are only requests id Values are different You can use the same domain name to combine different enterprises id Values are spliced into a complete enterprise details page url
- Judge whether the data in the enterprise details page is dynamically loaded ? Detect through the packet capturing tool , It is found that the enterprise details are dynamically loaded data in the details page
- Through the packet capturing tool, we can realize global search, locate and dynamically load the data packets corresponding to the data
post-url:http://125.35.6.84:81/xk/itownet/portalAction.do?method=getXkzsById
6 Request parameters :id=xxxxx The request to the json String is the enterprise detail information data we finally want
# -*- coding = utf-8 -*-
#@time :2020/5/17 18:22
#@file General Administration of Drug Administration .py
#@Software: PyCharm
import requests
from fake_useragent import UserAgent
import json
''' Through analysis ‘ It is found that this web page is a dynamically loaded web page , Right click the source code, there is nothing in it , It's a ajx Dynamic request for , from XHR Find post request url '''
if __name__ == '__main__':
IDlist = [] # All enterprises ID
infolist = []
post_url = "http://125.35.6.84:81/xk/itownet/portalAction.do?method=getXkzsList"
print(" Start ".center(10, "*"))
start_page = int(input(" Please enter the starting page number :"))
end_page = int(input(" Please enter the end page number ;"))
for page in range(start_page,end_page+1):
print(" The first %s Starting page -"%page)
fromdata={
"on":"true",
"page":page,
"pageSize":"15",
"productName":"",
"conditionType":"1",
"applyname":"",
"applysn":"",
}
r =requests.post(url=post_url,headers={
"User-Agent":UserAgent().chrome},data=fromdata)
# obtain json data
data_json = r.json()
# Traverse , obtain ID value , take data——json Response information , stay json Found in online parsing , It's a dictionary , Desired ID In this list Inside
for data in data_json["list"]:
IDlist.append(data["ID"])
# For details page post URL
homepage_post = "http://125.35.6.84:81/xk/itownet/portalAction.do?method=getXkzsById"
# Traverse the list , Package once per cycle
for id in IDlist:
data ={
"id":id,
}
r =requests.post(url=homepage_post,headers={
"User-Agent":UserAgent().random},data=data)
info =r.json()
# print(info)
infolist.append(info)
# Persistent storage
fp =open("infodata.json","w",encoding="utf8")
json.dump(infolist,fp=fp,ensure_ascii=False)
print(" end ".center(10,"*"))
版权声明
本文为[Zhao [email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/210/202207290520358054.html
边栏推荐
- Limitations of push down analysis
- You study, I reward, 21 day learning challenge | waiting for you to fight
- [flask introduction series] installation and configuration of flask Sqlalchemy
- Keyboard processing in jetpack compose
- postman接口测试|js脚本之阻塞休眠和非阻塞休眠
- C language interview preparation I (about understanding Department)
- C language data type
- Realize the effect of changing some colors of a paragraph of text
- [introduction to cryoelectron microscopy] Caltech open class course notes part 3:image formation
- String class
猜你喜欢

Do you want to meet all the needs of customers

佳木斯市场监管局开展防疫防虫害专题食品安全网络培训

An optimal buffer management scheme with dynamic thresholds paper summary
![[paper reading | cryoet] gum net: fast and accurate 3D subtomo image alignment and average unsupervised geometric matching](/img/dc/255bf122d5243f2a08ca0e03b53137.png)
[paper reading | cryoet] gum net: fast and accurate 3D subtomo image alignment and average unsupervised geometric matching

Technology sharing | quick intercom integrated dispatching system

Keyboard processing in jetpack compose

Implementation of simple cubecap+fresnel shader in unity

Day 014 二维数组练习

Compare three clock circuit schemes of single chip microcomputer

Cs61abc sharing session (VI) detailed explanation of program input and output - standard input and output, file, device, EOF, command line parameters
随机推荐
Rotation in model space and rotation in world space
Unity beginner 4 - frame animation and protagonist attack (2D)
JVM garbage collection mechanism (GC)
你学习·我奖励,21天学习挑战赛 | 等你来战
UPC little C's King Canyon
Actual measurement of boot and pH pins of buck circuit
Go 事,如何成为一个Gopher ,并在7天找到 Go 语言相关工作,第1篇
Autojs微信研究:微信自动发送信息机器人最终成品(有效果演示)
Do you want to meet all the needs of customers
"Swiss Army Knife" -nc in network tools
Solve the problem that the disk is full due to large files
Greenplus enterprise deployment
Phased learning about the entry-level application of SQL Server statements - necessary for job hunting (I)
功能自动化测试实施的原则以及方法有哪些?
[skill accumulation] presentation practical skill accumulation, common sentence patterns
佳木斯市场监管局开展防疫防虫害专题食品安全网络培训
Measured waveform of boot capacitor short circuit and open circuit of buck circuit
You study, I reward, 21 day learning challenge | waiting for you to fight
Prepare esp32 environment
FLink CDC 的mysql connector中,mysql的字段是varbinary, 官方