当前位置: 代码迷 >> 综合 >> aardio - 利用sunny修改网页显示内容
  详细解决方案

aardio - 利用sunny修改网页显示内容

热度:38   发布时间:2024-01-14 01:44:24.0

参考网友 

庄.园 (zhuang8750)

的文章:https://blog.csdn.net/zhuang8750/article/details/123488702?utm_source=app&app_version=5.1.1&code=app_1562916241&uLinkId=usr1mkqgl919blen

注意以下要点:

1、利用sunny库,拦截住request和response后,修改其内容。

2、sunny.start() 中指定代理端口号。只拦截自身进程不用开全局代理。

3、为实现拦截自身 web.view 数据,需要在web.view参数中使用代理,端口号要与sunny.start() 中指定的代理端口号一致:

      var wb = web.view(winform,,`--proxy-server="socks://127.0.0.1:2021"`);

4、如果要拦截自身 inet.http 数据,设置代理方式如下:

      inet.http(,"HTTP=HTTP://127.0.0.1:2021").get("http://www.baidu.com")

5、如果在 request 请求中修改 response 数据,将直接返回伪造的response数据,而不再去获取真实的response数据。

 相关例程代码:

import win.ui;
/*DSG{
   {*/
var winform = win.form(text="aardio利用sunny中间件实现拦截并修改网页内容";right=1025;bottom=680;border="thin";maximize=1)
winform.add()
/*}}*/import godking.sunny;
var sunny=godking.sunny();
import web.view;
var wb = web.view(winform,"c:\user",`--proxy-server="socks://127.0.0.1:2021"`);sunny.callback_http = function(winform,context,id,msgid,msgtype,mod,url,err,pid){// 注意:1、回调函数为线程函数;2、要重新引用godking.sunnyimport godking.sunny	import web.json;	if msgtype==godking.sunny.msgType.http_request and url="http://chengxu.online/" {//data为目标网页代码(去除不想要的内容后的代码)var data=/***<html><head><title>光庆·程序·在线</title><link rel="shortcut icon" href="/favicon.ico"><link rel="bookmark" href="/favicon.ico"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta content="all" name="Robots"><meta content="MSHTML 6.00.3790.2706" name="GENERATOR"><link href="images/Style.css" type="text/css" rel="stylesheet"></head><body bottommargin="0" leftmargin="0" topmargin="0" rightmargin="0"><table class="toptable" height="27" cellspacing="0" cellpadding="0" width="100%" align="center" border="0"><tbody><tr><td height="100"><img src="images/banner.gif"></td></tr></tbody></table><style type="text/css">table.change:hover{background-color:#eeeeee}</style><script type="text/javascript">function rowClick (fileurl) {window.open(fileurl);}</script><table width="100%" align="center"><tbody><tr><td style="WIDTH: 200px; HEIGHT: 21px; TEXT-ALIGN: center" align="left" valign="top"><table height="100%" width="200px"><tbody><tr height="36px"><td bgcolor="#3399ff" style="FONT-SIZE: 14px;FONT-WEIGHT: bold; COLOR: white; HEIGHT: 25px; TEXT-ALIGN: center; TEXT-DECORATION: none">首页 》 网站公告</td></tr><tr><td class="table" style="FONT-SIZE: 14px;padding:10;" width="200px" valign="top" height="100%">1、本站主要用来发布本人[光庆]原创的软件作品。<br>2、同时,搜集了一些比较好用的软件。特别是一些绿化的、无广告的软件,值得珍藏。<br>3、用来推荐一些比较好的软件下载站。<br>4、承接软件定做业务。<p>业务QQ:17950677<br>微信号:godking888</p></td></tr></tbody></table></td><td style="WIDTH:100%; HEIGHT: 21px" align="center" valign="top"><table style="WIDTH: 100%; HEIGHT: 182px"><tbody><form id="form1" name="form1" method="post" action="index.asp"></form><tr height="36px"><td colspan="3" valign="middle" bgcolor="#3399ff" style="FONT-SIZE: 14px;FONT-WEIGHT: bold; COLOR: white; TEXT-DECORATION: none">&nbsp;文件类型:<select name="ClassID" id="ClassID" style="FONT-SIZE: 14px;"><option value="0">全部类型</option><option value="11">aardio资源</option><option value="4">装机工具</option><option value="5">应用软件</option><option value="10">精品网站</option><option value="1">其它资料</option><option value="12">精彩文章</option></select>&nbsp;&nbsp;操作系统:<select name="System" id="System" style="FONT-SIZE: 14px;"><option value="">全部系统</option><option value="Win 32位">Win 32位</option><option value="Win 64位">Win 64位</option><option value="安卓系统">安卓系统</option><option value="网址">网址</option><option value="其他">其他</option></select>&nbsp;&nbsp;关键字:<input name="keyword" type="text" id="keyword" size="20" value="">&nbsp;&nbsp;<input type="submit" name="Submit" value="搜索"></td></tr><tr><td class="table" valign="top"><table width="100%" border="0" cellspacing="1" cellpadding="3" style="border-collapse: collapse;"><tbody><tr height="150"><td width="33%" height="80px"><table class="change" cellspacing="0" cellpadding="0" style="border:0px solid #f55901; border-collapse: collapse;background: #eeeeee;" width="100%" height="100%"><tbody><tr style="border-bottom: 0px solid #dddddd;"><td colspan="2" style="padding: 0 0 0 10; height:30px; font-size:18px; vertical-align: middle; background: #eeeeee;"><font style="background: red; font-size:14px; color: white; padding: 3 5; border-radius: 3px;">置顶</font><font style="font-size:18px; font-family: Microsoft YaHei;">aardio资源下载</font></td><td style="cursor:pointer; height: 30px; width: 80px; vertical-align: middle; background: #f55901;"><img onclick="rowClick('https://wws.lanzoui.com/b026gmeta')" src="images/view_btn.gif"> </td></tr><tr><td style="vertical-align: top; padding: 10px; width: 80px; "><div style="padding: 3px; width: 80px; height: 80px; overflow: hidden; border: 1px solid #BBBBBB; border-radius: 13px;"><img style="display:block; border-radius: 10px;" width="80" height="80" src="UploadPic/202110041531443238.png"></div></td><td height="100%" colspan="2" style="vertical-align: top; padding: 9px;"><p style="font-size:12px; color:#666666;">aardio资源&nbsp;/&nbsp;Win 32位&nbsp;/&nbsp;0 Byte<br>本人编写的aardio库等资源文件下载。使用方法可以参考本人CSDN博客,一般都有相关文章。<font color="red">浏览密码:123</font><br></p></td></tr></tbody></table></td><td width="33%" height="80px"><table class="change" cellspacing="0" cellpadding="0" style="border:0px solid #f55901; border-collapse: collapse;background: #eeeeee;" width="100%" height="100%"><tbody><tr style="border-bottom: 0px solid #dddddd;"><td colspan="2" style="padding: 0 0 0 10; height:30px; font-size:18px; vertical-align: middle; background: #eeeeee;"><font style="background: red; font-size:14px; color: white; padding: 3 5; border-radius: 3px;">置顶</font><font style="font-size:18px; font-family: Microsoft YaHei;">CSDN光庆的学习笔记</font></td><td style="cursor:pointer; height: 30px; width: 80px; vertical-align: middle; background: #f55901;"><img onclick="rowClick('https://blog.csdn.net/sdlgq')" src="images/view_btn.gif"> </td></tr><tr><td style="vertical-align: top; padding: 10px; width: 80px; "><div style="padding: 3px; width: 80px; height: 80px; overflow: hidden; border: 1px solid #BBBBBB; border-radius: 13px;"><img style="display:block; border-radius: 10px;" width="80" height="80" src="UploadPic/202108101503325112.png"></div></td><td height="100%" colspan="2" style="vertical-align: top; padding: 9px;"><p style="font-size:12px; color:#666666;">精品网站&nbsp;/&nbsp;网址&nbsp;/&nbsp;0 Byte<br>CSDN光庆的学习笔记,用来记录站长学习中积累的知识点。<br></p></td></tr></tbody></table></td><td width="33%" height="80px"><table class="change" cellspacing="0" cellpadding="0" style="border:0px solid #1e90ff; border-collapse: collapse;background: #eeeeee;" width="100%" height="100%"><tbody><tr style="border-bottom: 0px solid #dddddd;"><td colspan="2" style="padding: 0 0 0 10; height:30px; font-size:18px; vertical-align: middle; background: #eeeeee;"><font style="background: #f55901; font-size:14px; color: white; padding: 3 5; border-radius: 3px;">原创</font><font style="font-size:18px; font-family: Microsoft YaHei;">考勤管理系统(单机版)</font></td><td style="cursor:pointer; height: 30px; width: 80px; vertical-align: middle; background: #1e90ff;"><img onclick="rowClick('https://wwr.lanzoui.com/iLQ2Hsmlebg')" src="images/download_btn.gif"> </td></tr><tr><td style="vertical-align: top; padding: 10px; width: 80px; "><div style="padding: 3px; width: 80px; height: 80px; overflow: hidden; border: 1px solid #BBBBBB; border-radius: 13px;"><img style="display:block; border-radius: 10px;" width="80" height="80" src="UploadPic/202108141700586833.png"></div></td><td height="100%" colspan="2" style="vertical-align: top; padding: 9px;"><p style="font-size:12px; color:#666666;">应用软件&nbsp;/&nbsp;Win 32位&nbsp;/&nbsp;943 KB<br>考勤管理系统,登记员工每日考勤,含早班、白班、晚班、加班,自动生成每日考勤表,可统计每班签到人数、查看每个员工的考勤情况,实时查看欠班天数。默认登录授权密码:123。<br>密码:6kok<br></p></td></tr></tbody></table></td></tr><tr height="150"><td width="33%" height="80px"><table class="change" cellspacing="0" cellpadding="0" style="border:0px solid #1e90ff; border-collapse: collapse;background: #eeeeee;" width="100%" height="100%"><tbody><tr style="border-bottom: 0px solid #dddddd;"><td colspan="2" style="padding: 0 0 0 10; height:30px; font-size:18px; vertical-align: middle; background: #eeeeee;"><font style="background: #f55901; font-size:14px; color: white; padding: 3 5; border-radius: 3px;">原创</font><font style="font-size:18px; font-family: Microsoft YaHei;">中文打字练习</font></td><td style="cursor:pointer; height: 30px; width: 80px; vertical-align: middle; background: #1e90ff;"><img onclick="rowClick('https://wwr.lanzoui.com/io8qpsmksdg')" src="images/download_btn.gif"> </td></tr><tr><td style="vertical-align: top; padding: 10px; width: 80px; "><div style="padding: 3px; width: 80px; height: 80px; overflow: hidden; border: 1px solid #BBBBBB; border-radius: 13px;"><img style="display:block; border-radius: 10px;" width="80" height="80" src="UploadPic/202108141648393895.png"></div></td><td height="100%" colspan="2" style="vertical-align: top; padding: 9px;"><p style="font-size:12px; color:#666666;">应用软件&nbsp;/&nbsp;Win 32位&nbsp;/&nbsp;420 KB<br>中文练习工具,练习中文输入速度,提升中文输入能力。非常适合汉字录入人员练习使用。<br>密码:dw7u<br></p></td></tr></tbody></table></td><td width="33%" height="80px"><table class="change" cellspacing="0" cellpadding="0" style="border:0px solid #1e90ff; border-collapse: collapse;background: #eeeeee;" width="100%" height="100%"><tbody><tr style="border-bottom: 0px solid #dddddd;"><td colspan="2" style="padding: 0 0 0 10; height:30px; font-size:18px; vertical-align: middle; background: #eeeeee;"><font style="background: #f55901; font-size:14px; color: white; padding: 3 5; border-radius: 3px;">原创</font><font style="font-size:18px; font-family: Microsoft YaHei;">小键盘练习</font></td><td style="cursor:pointer; height: 30px; width: 80px; vertical-align: middle; background: #1e90ff;"><img onclick="rowClick('https://wwr.lanzoui.com/iDK54smk9dc')" src="images/download_btn.gif"> </td></tr><tr><td style="vertical-align: top; padding: 10px; width: 80px; "><div style="padding: 3px; width: 80px; height: 80px; overflow: hidden; border: 1px solid #BBBBBB; border-radius: 13px;"><img style="display:block; border-radius: 10px;" width="80" height="80" src="UploadPic/202108141636041668.png"></div></td><td height="100%" colspan="2" style="vertical-align: top; padding: 9px;"><p style="font-size:12px; color:#666666;">应用软件&nbsp;/&nbsp;Win 32位&nbsp;/&nbsp;465.5 KB<br>小键盘练习工具,练习小键盘输入速度,提升数字输入能力。非常适合柜台收银员练习使用。<br>密码:3xok<br></p></td></tr></tbody></table></td><td width="33%" height="80px"><table class="change" cellspacing="0" cellpadding="0" style="border:0px solid #1e90ff; border-collapse: collapse;background: #eeeeee;" width="100%" height="100%"><tbody><tr style="border-bottom: 0px solid #dddddd;"><td colspan="2" style="padding: 0 0 0 10; height:30px; font-size:18px; vertical-align: middle; background: #eeeeee;"><font style="background: #f55901; font-size:14px; color: white; padding: 3 5; border-radius: 3px;">原创</font><font style="font-size:18px; font-family: Microsoft YaHei;">算钞练习</font></td><td style="cursor:pointer; height: 30px; width: 80px; vertical-align: middle; background: #1e90ff;"><img onclick="rowClick('https://wwr.lanzoui.com/iow6dsmjxwj')" src="images/download_btn.gif"> </td></tr><tr><td style="vertical-align: top; padding: 10px; width: 80px; "><div style="padding: 3px; width: 80px; height: 80px; overflow: hidden; border: 1px solid #BBBBBB; border-radius: 13px;"><img style="display:block; border-radius: 10px;" width="80" height="80" src="UploadPic/202108141628166924.png"></div></td><td height="100%" colspan="2" style="vertical-align: top; padding: 9px;"><p style="font-size:12px; color:#666666;">应用软件&nbsp;/&nbsp;Win 32位&nbsp;/&nbsp;496.5 KB<br>算钞练习工具,练习手动算钞能力,给出钞票面值和张数,快速计算出金额总数。非常适合柜台收银员练习使用。<br>密码:7cfw<br></p></td></tr></tbody></table></td></tr><tr height="150"><td width="33%" height="80px">              </td></tr><tr><td colspan="3"><table align="center"><tbody><tr><td>共 <b>68</b> 个文件&nbsp;&nbsp;首页&nbsp;上一页&nbsp;<a href="index.asp?ClassID=0&amp;System=&amp;keyword=&amp;page=2">下一页</a>&nbsp;<a href="index.asp?ClassID=0&amp;System=&amp;keyword=&amp;page=5">尾页</a>&nbsp;页次:<strong><font color="red">1</font>/5</strong>页 &nbsp;<b>15</b>个文件/页&nbsp;转到:<select name="page" size="1" onchange="javascript:window.location='index.asp?ClassID=0&amp;System=&amp;keyword=&amp;page='+this.options[this.selectedIndex].value;"><option value="1" selected="">第1页</option><option value="2">第2页</option><option value="3">第3页</option><option value="4">第4页</option><option value="5">第5页</option></select></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr></tr></tbody></table><table width="100%" align="center" cellspacing="1" cellpadding="1" class="bottomtable bgcolor_1"><tbody><tr><td align="middle" colspan="3" rowspan="3" class="copyright_td">? CopyRight 2020-2028 Design By:光庆·程序·在线&nbsp;&nbsp;QQ:17950677&nbsp;&nbsp;微信:godking888&nbsp;&nbsp;页面执行时间:0.07813 秒</td></tr><tr></tr><tr></tr></tbody></table></body></html>***/var response = godking.sunny.httpResponse(msgid);response.setBody(data);	//设置返回网页内容为自定义内容	}	
}sunny.start(2021/*代理端口*/,/*开启全局IE代理*/,/*上游代理*/,/*上游代理规则*/,/*脚本*/,/*强制TCP*/,/*自动unGzip*/,winform)
wb.go("http://chengxu.online/"); //打开目标网站winform.onClose = function(hwnd,message,wParam,lParam){//关闭窗口时停止sunny拦截sunny.stop();	
}winform.show();
win.loopMessage();