当前位置:网站首页>Is it too troublesome to turn pages manually when you encounter a form? I'll teach you to write a script that shows all the data on one page
Is it too troublesome to turn pages manually when you encounter a form? I'll teach you to write a script that shows all the data on one page
2022-06-11 22:37:00 【Data ape vision】
The confusion of Internet users
People who read this article , It must be all Internet users . You must have met 「 form 」.
When we read the tables , There may be this confusion :
- The form does not support keyword search
- The table does not support sorting by a column
- Each page of the form can only show 10 Data , Need to keep turning pages , To see all the content
What shall I do? ?
If only one page of the table could show all the data !
In this case :
- Keyword search can be done through the browser 「 Search for 」 Function realization (
Ctrl+ForCommand+F). - Sorting can be realized by referring to my next article ( Coming soon ).
- There is no need to turn pages manually .
Next , Let me HullQin To provide you with a solution , Let the table show all the data on one page !
Solution
Take nuggets for example
We found that , This is called list_by_user Of API, Is the back-end paging API.
We just need to iterate through the request , You can get all the data in the form , Then let the front end be displayed at one time ~
Here you are 2 Two problems need to be solved :
- I'm going to cycle through the interface by page , So as to obtain all the data of the table .
- I want to make the front-end Nuggets code request when , Only request 1 Time , Get all the data . In this way, it can be displayed at one time .
Solve the 1 A question : Get all the data
Let's open the browser's developer tools , open Network( The Internet ) panel , Found this called list_by_user Of API, The required data of the table is returned .
We need to modify it page_no Parameters , Then iterate over it many times , Always request this interface , Until the last page .
Chrome The most convenient thing is , Can directly Copy as fetch, After clicking , You can copy the request fetch edition , do 「 Replay attack 」 It's too convenient ,Chrome The intimate function of is really too painful !


Of course, the above 「 Replay attack 」 Use quotation marks , It's not really a replay attack , We just did one more query , It does not change the data state of the back end .
below , Change it fetch function , We need to save its results .
This API The return result of is :

Our ultimate goal is , hold data All the data in are integrated into the same array .
const result = [];
const res = await fetch('... What you copied ');
const data = await res.json();
result.push(...data.data);
Copy code 
Next , We add... To the above logic for Loop to achieve paging access :
const result = [];
// Don't put too much pressure on Nuggets , We define a sleep function ,1 Just ask once per second
const sleep = async () => new Promise(resolve => setTimeout(resolve, 1000));
for (let i = 1; i <= 2; i++) { // Note that you need to i The maximum value of is changed to , See how many times you need to download all the data .
const res = await fetch("https://api.juejin.cn/content_api/v1/article/list_by_user? Change it to your parameter !", {
"headers": { "content-type": "application/json" },
"body": "{\"page_size\":10,\"page_no\":" + i + ",\"audit_status\":null}",
"method": "POST",
"mode": "cors",
"credentials": "include",
});
const data = await res.json();
result.push(...data.data);
await sleep(); // Don't put too much pressure on Nuggets , We 1 Just ask once per second
}
Copy code 
Now? ,result That's all the data in our table !
边栏推荐
猜你喜欢

Learn to crawl for a month and earn 6000 a month? Don't be fooled. The teacher told you the truth about the reptile

5. Xuecheng project Alipay payment

Tkinter学习笔记(二)

图的基本操作(C语言)

360 online enterprise security cloud is open to small, medium and micro enterprises for free

Tkinter学习笔记(三)

Explain asynchronous tasks in detail: the task of function calculation triggers de duplication

Why is the printer unable to print the test page

Php+mysql library management system (course design)

Only three steps are needed to learn how to use low code thingjs to connect with Sen data Dix data
随机推荐
SVN本地部署server和cleint 并用阿里云盘自动备份
How to adjust the font blur of win10
Php+mysql library management system (course design)
3.2 naming rules of test classes
Tkinter study notes (III)
Exercise 9-6 statistics of student scores by grade (20 points)
链表基本操作与题型总结
消息队列存储消息数据的 MySQL表
机器学习之Logistic回归简单实例
Number of classified statistical characters (15 points)
[Yu Yue education] calculus of Zhejiang University in autumn and winter 2021 (I) reference materials
完好性简要介绍
Three years of college should be like this
Exercise 9-5 address book sorting (20 points)
Explain asynchronous tasks in detail: the task of function calculation triggers de duplication
【Uniapp 原生插件】商米钱箱插件
Exercise 6-6 using a function to output an integer in reverse order (20 points)
Exercise 8-8 judging palindrome string (20 points)
Are you still using localstorage directly? It's time to raise the bar
Simple example of logistic regression for machine learning