aardio利用sunny中间件实现只显示网页部分内容

        前两天有个朋友有个需求,在利用aardio开发的软件打开一个网站时,首页只想显示部分内容,其他信息不显示。aardio的web.form有一个显示部分网页的范例,可以实现需求,但是用这种方式打开的网页,后面再打开的网页也只能显示一部分。突然想到光庆封装的sunny库 (下载地址:光庆·程序·在线)有一个例子是替换网页中图片,由此联想,可以网页内容也可以修改。经征得光庆同意,下面以光庆·程序·在线网站为例介绍实现过程。

光庆·程序·在线首页内容如下图:

 现在想要打开网页时只显示下图红框中的内容及底部翻页内容和版权信息:

实现步骤:1、获取首页网页源码,去除不想显示的内容,然后作为要显示的内容保存,这里注意把编码改为utf-8格式,否则会现出乱码。

                  2、利用sunny库获取请求光庆·程序·在线首页返回的网页源码;

                  3、用sunny库的setData设置返回的数据为第一步保存的网页源码。

实现效果如下(下面部分没有有了,但其他效果和官网一样):

 下面上代码:

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:\user1",`--proxy-server="socks://127.0.0.1:2021"`);

sunny.callback_http = function(winform,id,msgid,msgtype,mod,url,pid,notice,err){
	// 注意:1、回调函数为线程函数;2、要重新引用godking.sunny
	import godking.sunny	
	import web.json;	
	var response = godking.sunny.httpResponse(msgid);
		
	if msgtype==godking.sunny.msgType.http_response 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>
		***/
		response.setData(data);	//设置返回网页内容为自定义内容	
	}	
}

sunny.start(2021/*代理端口*/,false/*过滤正文*/,isGlobal/*全局代理*/,true/*禁止压缩*/,winform/*传递窗口*/);
wb.go("http://chengxu.online/"); //打开目标网站


winform.onClose = function(hwnd,message,wParam,lParam){//关闭窗口时停止sunny拦截
    sunny.stop();	
}

winform.show();
win.loopMessage();

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值