aardio - 【库】webPageOperation网页操作类

功能介绍:

初步封装,用来网页填表、操作网页。

可操作web.form、web.view、web.view2等浏览器组件。

下载地址:

http://chengxu.online → aardio资源下载 → webPageOperation.rar

效果:

aardio - 【库】webPageOperation网页操作类_第1张图片

 示例代码:

import win.ui;
/*DSG{{*/
var winform = win.form(text="aardio form";right=759;bottom=469)
winform.add(
button={cls="button";text="打开百度图片";left=220;top=400;right=340;bottom=450;z=2};
button2={cls="button";text="搜索";left=410;top=400;right=530;bottom=450;z=3};
custom={cls="custom";text="自定义控件";left=50;top=30;right=700;bottom=380;z=1}
)
/*}}*/

import web.view
import console
var wb = web.view(winform.custom)
wb.go("http://www.baidu.com")

winform.button.oncommand = function(id,event){
	import godking.webPageOperation;
	var wpo = godking.webPageOperation(wb);
	
	// 点击"图片"连接
	var s = "#s-top-left > a:nth-child(6)";
	wpo.bySelector( s ).click();
}

winform.button2.oncommand = function(id,event){
	import godking.webPageOperation;
	var wpo = godking.webPageOperation(wb);
	
	// 填写搜索框内容
	var s = "#kw";
	wpo.bySelector( s ).setValue("光庆aardio");
		
	// 表单提交
	var tagname = "form"
	wpo.byTagNameS( tagname,1 ).submit();	
}

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

一个使用key库进行键盘输入的登录案例:

aardio - 【库】webPageOperation网页操作类_第2张图片

import win.ui;
/*DSG{{*/
var winform = win.form(text="aardio form";right=569;bottom=609)
winform.add(
button={cls="button";text="Button";left=210;top=550;right=330;bottom=590;z=2};
custom={cls="custom";text="自定义控件";left=10;top=10;right=550;bottom=530;z=1}
)
/*}}*/

import web.view2
var wb = web.view2(winform.custom)
wb.go("https://zwxt.mca.gov.cn/jmgc-mbs-front/login.html")

winform.button.oncommand = function(id,event){
	import godking.webPageOperation
	var wp = godking.webPageOperation( wb )
	import key
	
	//选择行政单位
	wp.bySelector( "#roleId > div > div > div" ).click()
	wp.bySelector( "body > div:nth-child(25) > div > div> div> ul> li:nth-child(3)" ).click()
	win.delay(500)
	
	//输入用户名
	wb.focus()
	wp.bySelector( "#username" ).focus()
	key.sendString("user",50)
	
	//输入密码
	wb.focus()
	wp.bySelector( "#password" ).focus()
	key.sendString("12345678",50)
	
	//输入验证码
	var code = wp.bySelector( "span.yzmCode" ).getInnerText()
	wp.bySelector( "#checkCode" ).focus()
	key.sendString(code,50)
	
	//点击登录按钮
	wp.bySelector( "#sbbtn" ).click()

}

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

一个鼠标点击让元素获取焦点,并用键盘输入的登录案例:

aardio - 【库】webPageOperation网页操作类_第3张图片

import win.ui;
/*DSG{{*/
var winform = win.form(text="WebView2 - 调用百度低代码前端框架 amis";right=439;bottom=489)
winform.add(
button={cls="button";text="Button";left=140;top=420;right=280;bottom=480;z=1}
)
/*}}*/

import web.view;
var wb = web.view(winform);
	
wb.export({
	getAmisJson  = function(){
		return {
			"type":"page",
			"title":"表单页面", 
			"body":{
				"type":"form",
				"mode":"horizontal",
				"api":"/saveForm",
				"body":{
					{"type":"input-text","name":"name","label":"Name","required":true},
					{"type":"input-email","name":"email","label":"Email","required":true},
					{"type":"static-tpl","tpl":"生成的id为:${id}"}
				}, 
			}
		};
	}; 
})

import wsock.tcp.asynHttpServer;
var httpServer = wsock.tcp.asynHttpServer(); 
httpServer.run( {
	["/index.html"] = /**


	
	 
	
	
	
	
	
	
	
**/; ["/saveForm"] = function(response,request){ var data = request.postJson();//读取表单请求发送的数据,已解析为 aardio 对象 response.write({ "status": 0, "msg": "保存成功", "data": { "id": 1 } }) }; }); wb.go( httpServer.getUrl("index.html") ) wb.waitEle(".antd-TplField") //============================================================================================================ import godking.webPageOperation var w = godking.webPageOperation( wb ) //===========演示元素组操作 var s = w.bySelectorS(".antd-TplField") s.byIndex(1).setInnerHTML( "填写表单演示程序:" ) s.byIndex(2).setInnerText( "请正确填写以下内容:" ) s.byIndex(3).setInnerText( "姓名:" ) s.byIndex(4).setInnerText( "邮箱:" ) //===========演示鼠标点击元素,键盘输入字符 winform.button.oncommand = function(id,event){ // 鼠标点击 import mouse mouse.moveToWindow(195,116,winform.hwnd,1000) mouse.click() //键盘输入 import key key.sendString("光庆",0) key.press(0x9/*_VK_TAB*/) key.sendString("[email protected]",0) //按钮提交 w.bySelector( "button" ).click() } winform.show(); win.loopMessage();

遍历获取子元素案例:

aardio - 【库】webPageOperation网页操作类_第4张图片

代码:

import win.ui;
/*DSG{{*/
var winform = win.form(text="aardio form";right=759;bottom=469)
winform.add(
custom={cls="custom";text="自定义控件";left=20;top=10;right=730;bottom=410;z=1}
)
/*}}*/

winform.show();
import web.view;
import console;
import godking.webPageOperation;

var wb = web.view(winform.custom);
wb.go("http://api.tiankongapi.com/api.php/provide/vod/at/xml")


var wpo = godking.webPageOperation(wb);
var s = wpo.bySelector( "body > rss > list").byChildS();
for(i=1;s.count();1){
	var ss = s.byIndex( i ).byChildS();
	for(n=1;ss.count();1){
		console.dump(ss.byIndex( n ).getTag()+":"+ss.byIndex( n ).getInnerHTML())
	}
	console.dump('')
}
win.loopMessage();

 

你可能感兴趣的:(库,aardio,aardio)