“ Yuema约吗?一起学技术,一起成长!学海无涯 高人带路系列”
程序的世界,就是有坑的地方!分享踩坑的心得与体验!每天分享一点点!
关注公众号,进入学海无涯,高人带路模式!!
学会一招神技能
今天遇到一个需要批量调接口的场景,从数据库中查出上万条数据,再按接口规则生成带get参数的url请求,还要带登陆状态。
一、从数据库中捞出数据
将查出来的数据贴到notepad++中,大概是这样子的数据,示范一下
1 a 11
2 b 22
3 c 33
4 d 44
5 e 55
6 f 66
7 g 77
8 h 88
9 i 99
将空格换成%20,这个直接把空格换掉就是,示例数据没有演示这个场景,自行脑补一下。
二、使用chrome生成一个带cookie的请求
操作截图如上图所示,是不是很方便,cookies都带上了,有登陆状态,调接口相当方面。
curl "http://yue.ma/?i=9&m=6&p=11" -H "Connection: keep-alive" -H "Cache-Control: max-age=0" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3" -H "Accept-Encoding: gzip, deflate" -H "Accept-Language: zh-CN,zh;q=0.9" -H "Cookie: __51cke__=; __tins__18251311=^%^7B^%^22sid^%^22^%^3A^%^201575548726427^%^2C^%^20^%^22vd^%^22^%^3A^%^203^%^2C^%^20^%^22expires^%^22^%^3A^%^201575551216664^%^7D; __51laig__=3" --compressed --insecure
三、使用正则替换,生成批量脚本
制作一个脚本正则模板
curl "http://yue.ma/?i=$1&m=$2&p=$3" -H "Connection: keep-alive" -H "Cache-Control: max-age=0" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3" -H "Accept-Encoding: gzip, deflate" -H "Accept-Language: zh-CN,zh;q=0.9" -H "Cookie: __51cke__=; __tins__18251311=^%^7B^%^22sid^%^22^%^3A^%^201575548726427^%^2C^%^20^%^22vd^%^22^%^3A^%^203^%^2C^%^20^%^22expires^%^22^%^3A^%^201575551216664^%^7D; __51laig__=3" --compressed --insecure
使用notepad++替换功能
查找目标填写:
^([^\t]+)\t([^\t]+)\t([^\t]+)$
替换为填写:
curl "http://yue.ma/?i=$1&m=$2&p=$3" -H "Connection: keep-alive" -H "Cache-Control: max-age=0" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3" -H "Accept-Encoding: gzip, deflate" -H "Accept-Language: zh-CN,zh;q=0.9" -H "Cookie: __51cke__=; __tins__18251311=^%^7B^%^22sid^%^22^%^3A^%^201575548726427^%^2C^%^20^%^22vd^%^22^%^3A^%^203^%^2C^%^20^%^22expires^%^22^%^3A^%^201575551216664^%^7D; __51laig__=3" --compressed --insecure
生成脚本
curl "http://yue.ma/?i=1&m=a&p=11" -H "Connection: keep-alive" -H "Cache-Control: max-age=0" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: Mozilla/5.0 Windows NT 10.0; Win64; x64 AppleWebKit/537.36 KHTML, like Gecko Chrome/78.0.3904.108 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3" -H "Accept-Encoding: gzip, deflate" -H "Accept-Language: zh-CN,zh;q=0.9" -H "Cookie: __51cke__=; __tins__18251311=^%^7B^%^22sid^%^22^%^3A^%^201575548726427^%^2C^%^20^%^22vd^%^22^%^3A^%^203^%^2C^%^20^%^22expires^%^22^%^3A^%^201575551216664^%^7D; __51laig__=3" --compressed --insecure
curl "http://yue.ma/?i=2&m=b&p=22" -H "Connection: keep-alive" -H "Cache-Control: max-age=0" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: Mozilla/5.0 Windows NT 10.0; Win64; x64 AppleWebKit/537.36 KHTML, like Gecko Chrome/78.0.3904.108 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3" -H "Accept-Encoding: gzip, deflate" -H "Accept-Language: zh-CN,zh;q=0.9" -H "Cookie: __51cke__=; __tins__18251311=^%^7B^%^22sid^%^22^%^3A^%^201575548726427^%^2C^%^20^%^22vd^%^22^%^3A^%^203^%^2C^%^20^%^22expires^%^22^%^3A^%^201575551216664^%^7D; __51laig__=3" --compressed --insecure
curl "http://yue.ma/?i=3&m=c&p=33" -H "Connection: keep-alive" -H "Cache-Control: max-age=0" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: Mozilla/5.0 Windows NT 10.0; Win64; x64 AppleWebKit/537.36 KHTML, like Gecko Chrome/78.0.3904.108 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3" -H "Accept-Encoding: gzip, deflate" -H "Accept-Language: zh-CN,zh;q=0.9" -H "Cookie: __51cke__=; __tins__18251311=^%^7B^%^22sid^%^22^%^3A^%^201575548726427^%^2C^%^20^%^22vd^%^22^%^3A^%^203^%^2C^%^20^%^22expires^%^22^%^3A^%^201575551216664^%^7D; __51laig__=3" --compressed --insecure
curl "http://yue.ma/?i=4&m=d&p=44" -H "Connection: keep-alive" -H "Cache-Control: max-age=0" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: Mozilla/5.0 Windows NT 10.0; Win64; x64 AppleWebKit/537.36 KHTML, like Gecko Chrome/78.0.3904.108 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3" -H "Accept-Encoding: gzip, deflate" -H "Accept-Language: zh-CN,zh;q=0.9" -H "Cookie: __51cke__=; __tins__18251311=^%^7B^%^22sid^%^22^%^3A^%^201575548726427^%^2C^%^20^%^22vd^%^22^%^3A^%^203^%^2C^%^20^%^22expires^%^22^%^3A^%^201575551216664^%^7D; __51laig__=3" --compressed --insecure
curl "http://yue.ma/?i=5&m=e&p=55" -H "Connection: keep-alive" -H "Cache-Control: max-age=0" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: Mozilla/5.0 Windows NT 10.0; Win64; x64 AppleWebKit/537.36 KHTML, like Gecko Chrome/78.0.3904.108 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3" -H "Accept-Encoding: gzip, deflate" -H "Accept-Language: zh-CN,zh;q=0.9" -H "Cookie: __51cke__=; __tins__18251311=^%^7B^%^22sid^%^22^%^3A^%^201575548726427^%^2C^%^20^%^22vd^%^22^%^3A^%^203^%^2C^%^20^%^22expires^%^22^%^3A^%^201575551216664^%^7D; __51laig__=3" --compressed --insecure
curl "http://yue.ma/?i=6&m=f&p=66" -H "Connection: keep-alive" -H "Cache-Control: max-age=0" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: Mozilla/5.0 Windows NT 10.0; Win64; x64 AppleWebKit/537.36 KHTML, like Gecko Chrome/78.0.3904.108 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3" -H "Accept-Encoding: gzip, deflate" -H "Accept-Language: zh-CN,zh;q=0.9" -H "Cookie: __51cke__=; __tins__18251311=^%^7B^%^22sid^%^22^%^3A^%^201575548726427^%^2C^%^20^%^22vd^%^22^%^3A^%^203^%^2C^%^20^%^22expires^%^22^%^3A^%^201575551216664^%^7D; __51laig__=3" --compressed --insecure
curl "http://yue.ma/?i=7&m=g&p=77" -H "Connection: keep-alive" -H "Cache-Control: max-age=0" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: Mozilla/5.0 Windows NT 10.0; Win64; x64 AppleWebKit/537.36 KHTML, like Gecko Chrome/78.0.3904.108 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3" -H "Accept-Encoding: gzip, deflate" -H "Accept-Language: zh-CN,zh;q=0.9" -H "Cookie: __51cke__=; __tins__18251311=^%^7B^%^22sid^%^22^%^3A^%^201575548726427^%^2C^%^20^%^22vd^%^22^%^3A^%^203^%^2C^%^20^%^22expires^%^22^%^3A^%^201575551216664^%^7D; __51laig__=3" --compressed --insecure
curl "http://yue.ma/?i=8&m=h&p=88" -H "Connection: keep-alive" -H "Cache-Control: max-age=0" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: Mozilla/5.0 Windows NT 10.0; Win64; x64 AppleWebKit/537.36 KHTML, like Gecko Chrome/78.0.3904.108 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3" -H "Accept-Encoding: gzip, deflate" -H "Accept-Language: zh-CN,zh;q=0.9" -H "Cookie: __51cke__=; __tins__18251311=^%^7B^%^22sid^%^22^%^3A^%^201575548726427^%^2C^%^20^%^22vd^%^22^%^3A^%^203^%^2C^%^20^%^22expires^%^22^%^3A^%^201575551216664^%^7D; __51laig__=3" --compressed --insecure
curl "http://yue.ma/?i=9&m=i&p=99
" -H "Connection: keep-alive" -H "Cache-Control: max-age=0" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: Mozilla/5.0 Windows NT 10.0; Win64; x64 AppleWebKit/537.36 KHTML, like Gecko Chrome/78.0.3904.108 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3" -H "Accept-Encoding: gzip, deflate" -H "Accept-Language: zh-CN,zh;q=0.9" -H "Cookie: __51cke__=; __tins__18251311=^%^7B^%^22sid^%^22^%^3A^%^201575548726427^%^2C^%^20^%^22vd^%^22^%^3A^%^203^%^2C^%^20^%^22expires^%^22^%^3A^%^201575551216664^%^7D; __51laig__=3" --compressed --insecure
./bash.sh
作者:钟代麒
出处:http://www.jishudao.com/
版权归作者所有,转载请注明出处