爬虫工具—whistle安装与使用
2021-07-27 本文已影响0人
Jesscia_Liu
一.whistle安装
1.whistle安装步骤
1).终端使用npm命令安装whistle
$ npm install -g whistle
2).终端启动whistle
$ w2 start
[i] whistle@2.7.7 restarted
[i] 1. use your device to visit the following URL list, gets the IP of the URL you can access:
http://127.0.0.1:8899/
http://192.168.199.200:8899/
Note: If all the above URLs are unable to access, check the firewall settings
For help see https://github.com/avwo/whistle
[i] 2. configure your device to use whistle as its HTTP and HTTPS proxy on IP:8899
[i] 3. use Chrome to visit http://local.whistlejs.com/ to get started
3).whistle其他操作
- 关闭whistle
$ w2 stop
- 重启whistle
$ w2 restart
- whistle帮助
$ w2 help
2.打开whistle后台管理页面
- 在浏览器输入127.1:8899进入whistle后台管理页面
二.whistle插件配置
1. 下载SwitchyOmega插件
1)Firefox下载方法
- 工具-扩展和主题-搜索SwitchyOmega-添加组件
2)chrome下载方法
- google搜索SwitchyOmega,选择chrome 网上应用店安装SwitchyOmega

- 选择添加至Chrome
2.新建情景模式
- 建好后,启动whistle的配套情景模式,可在whistle后台管理页面查看页面访问情况
1)浏览器配置

3.手机-新建情景模式
1.iPhone配置
- 设置-无线局域网,切换到和电脑同一局域网下
- 进入局域网详情-配置HTTP代理-手动输入服务器:127.0.0.1和端口8899,存储退出
- 配置完成,可以在电脑上的浏览器whistle后台管理页面查看手机访问网址情况
三.whistle后台管理页面调试
1.打开whistle管理后台步骤
1) 在浏览器输入127.1:8899进入whistle后台管理页面
- 前提:保持终端开启whistle
$ w2 start
2) SwitchyOmega切换到刚刚配置好的whistle

3) 这时访问其他网站,就会在whistle后台管理页面显示

4) 如果要支持HTTPS还需要下载证书
2.Network使用
1)使用settings配置过滤条件等
- 过滤只显示www.baidu.com的请求,需要Clear后重新访问baidu

2).使用Inspectors
- 可以看到Request和Response详情,其中包含Header等参数信息
3).使用Composer
- 用于调试Rules,调试结果在Body或JSONView中查看
- 调试完毕需要写到左侧菜单的Rules下,再次访问网站才能看到修改效果

3.Rules使用
I.常用Rules介绍
# 规则:pattern operatorURI(即:自定义域名或URL+空格+本地目录路径)
www.mydemo.com/ln/ file:///Users/ln/Desktop/Python练习100道/index.html
www.mydemo.com/index/ file:///Users/ln/Desktop/Python练习100道/index2.html
#api.weibo.cn/2/comments/build_comments resMerge://(tip_msg=显示微博评论30天内博主拉黑人数&tip_close_disable=1)
api.weibo.cn/2/comments/build_comments resMerge://{demo.json}
api.weibo.cn/2/statuses/extend resMerge://{status.json}
api.weibo.cn/2/searchall resMerge://{test1.json}
#重定向
# https://www.baidu.com/ redirect://https://www.qq.com/
# hosts
# 127.0.0.1 www.mydemo.com
# 端口映射
# 127.0.0.1:8899 www.baidu.com
# CNAME
# host://www.qq.com www.mydemo.com
# 本地替换
# www.mydemo.com file:///Users/ln/Desktop/Python练习100道/index2.html
# 请求转发
# www.mydemo.com www.aliexpress.com
# 注入html、js、css
# www.mydemo.com js://D:/test/test.js
# 调试远程页面
# www.mydemo.com weinre://test
# log
# www.mydemo.com log://{test.js}
# resBody替换为values里面的内容
# www.mydemo.com resBody://{test.txt}
# 带模板解析
#www.mydemo.com resBody://`{test.json}`
# 内联多行操作值(带模板解析)
# www.mydemo.com file://`{test123.html}`
# ```test123.html
# Hello ${url}.
# Hello world1.
# Hello world2.
# ```
# 禁用请求的缓存,只要经过代理且匹配到的请求都不会使用缓存
# 跟 cache 协议的区别是,cache 只是用来设置响应的缓存头
# wwww.test.com disable://cache
# 禁用请求和响应的cookie
# wwww.test.com disable://cookie # 也可以写成复数形式cookies
# 只禁用请求的cookie
# wwww.test.com disable://reqCookie # 也可以写成复数形式reqCookies
# 只禁用响应的cookie
# wwww.test.com disable://resCookie # 也可以写成复数形式reqCookies
# 删除ua
# wwww.test.com disable://ua
# 删除referer
# wwww.test.com disable://referer
# 删除csp策略
# wwww.test.com disable://csp
# 禁用timeout,默认情况下whistle对每个请求如果36s内没有发生数据传输,会认为请求超时
# wwww.test.com disable://timeout
# 把301转成302,防止cache
# wwww.test.com disable://301
# 禁用https拦截
# wwww.test.com disable://intercept
# 不缓存远程的dns(通过whistle配置的host是不会缓存),主要用于测试网页的极端情况的加载速度
# wwww.test.com disable://dnsCache
# 禁用代理服务器请求链接复用
# wwww.test.com disable://keepAlive
# 删除请求头 `x-requested-with`
# wwww.test.com disable://ajax
# 也可以同时禁用多个
# www.example.com disable://cache|cookie|ua|referer|csp|timeout|301|intercept|dnsCache|keepAlive
4.Values使用
- 用于定义一些Rules用到的值,可以替换网页的页面内容
- 常用来定义默认的json,注意json文件必须要加后缀.json,否则Rules识别不了