aardio网页组件:webPageOperation

2023-12-14 02:45

本文主要是介绍aardio网页组件:webPageOperation,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

webPageOperation是webview的初步封装,用来网页填表、操作网页。可操作web.form、web.view、web.view2等浏览器组件。
1

使用方法

首先把webPageOperation.aardio(源码在后面)放到~\lib\godking目录下,然后新建窗口项目:

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=9;top=13;right=744;bottom=386;ah=1;aw=1;z=1}
)
/*}}*/import web.view
import console
var wb = web.view(winform.custom)
wb.go("https://www.sogou.com/")winform.button.oncommand = function(id,event){import godking.webPageOperation;var wpo = godking.webPageOperation(wb);// 点击"图片"连接var s = "#weixinch";wpo.bySelector( s ).click();
}winform.button2.oncommand = function(id,event){import godking.webPageOperation;var wpo = godking.webPageOperation(wb);// 填写搜索框内容var s = "#query";wpo.bySelector( s ).setValue("光庆aardio");// 表单提交var tagname = "form"wpo.byTagNameS( tagname,1 ).submit();	
}winform.show();
win.loopMessage();

组件源码

//webPageOperation 网页操作
//光庆封装 http://chengxu.online
//V1.1.1
//2023-06-05
//参考文档: https://developer.mozilla.org/zh-CN/docs/Web/API
/*
更新日志1.1.1 改进S结尾的操作集合,增加 byIndex() 函数,改进 byChildS() 和 byParent() 函数命名。1.1.0 支持 parentNode() 父元素操作集 和 childNodes() 子元素操作集。内置find函数,可寻找指定元素并返回操作集,但速度很慢。1.0.0 初步封装
Selector(CSS选择器)参考手册: https://www.runoob.com/cssref/css-selectors.htmlhttps://m.w3cschool.cn/cssref/css-selectors.html
bySelector(querySelector)使用文档:https://www.runoob.com/jsref/met-document-queryselector.html	https://m.w3cschool.cn/jsref/met-element-queryselector.html
*/
namespace godking// 对象操作类
class_func = class {ctor( webview,funcName,Selector="",index,childNodes="",childIndex){if index this.index = "[" ++(index-1)++ "]" else this.index = "";if childIndex this.childIndex = "[" ++(childIndex-1)++ "]" else this.childIndex = "";var childNodesIndex = childNodes ++ this.childIndex;};getProp = function(Prop){Prop:="value";return webview.eval("document." ++ funcName ++ "('" ++Selector++ "')" ++ this.index ++ childNodesIndex ++ "." ++Prop);}setProp = function(Prop,v=""){Prop:="value";if type(v)==type.string v="'" ++v++ "'";return webview.doScript("document." ++ funcName ++ "('" ++Selector++ "')" ++ this.index ++ childNodesIndex ++ "." ++Prop++ "=" ++v);}		count = function(){var t;if childNodes {t = webview.eval("document." ++ funcName ++ "('" ++Selector++ "')" ++ this.index ++ childNodes);}else{t = webview.eval("document." ++ funcName ++ "('" ++Selector++ "')");}if type(t) == type.table return ..table.count(t);else return 0;}click = function(){return webview.doScript("document." ++ funcName ++ "('" ++Selector++ "')" ++ this.index ++ childNodesIndex ++ ".click()");}submit = function(){return webview.doScript("document." ++ funcName ++ "('" ++Selector++ "')" ++ this.index ++ childNodesIndex ++ ".submit()");}getValue = function() { return this.getProp("value") }; setValue = function(v) { return this.setProp("value",v) }; getText = function() { var t = this.getProp("value"); if t!==null return tostring(t); }; setText = function(v) { return this.setProp("value",tostring(v)) }; getChecked = function() { return this.getProp("checked") }; setChecked = function(v=1) { return this.setProp("checked",v?1:0) }; getInnerText = function() { return this.getProp("innerText") }; setInnerText = function(v="") { return this.setProp("innerText",v) }; getOuterText = function() { return this.getProp("outerText") }; setOuterText = function(v="") { return this.setProp("outerText",v) }; getOuterHTML = function() { return this.getProp("outerHTML") }; setOuterHTML = function(v="") { return this.setProp("outerHTML",v) }; getInnerHTML = function() { return this.getProp("innerHTML") }; setInnerHTML = function(v="") { return this.setProp("innerHTML",v) }; getSelectedItemIndex = function(){var idx = this.getProp("selectedIndex"); if idx!==null return idx+1; }setSelectedItemByIndex = function(v){v:=1; v-=1; return this.setProp("selectedIndex",v)}getSelectedItemText = function(){var idx = this.getProp("selectedIndex"); if idx===null return ; return webview.eval("document." ++ funcName ++ "('" ++Selector++ "')" ++ this.index ++ childNodesIndex ++ ".options.item(" ++idx++ ").text");}setSelectedItemByText = function(v=""){for(i=1;this.count();1){if webview.eval("document." ++ funcName ++ "('" ++Selector++ "')" ++ this.index ++ childNodesIndex ++ ".options.item(" ++(i-1)++ ").text")==v {return webview.doScript("document." ++ funcName ++ "('"+Selector+"')" ++ this.index ++ childNodesIndex ++ ".selectedIndex=" ++(i-1));}}} getItemText = function(v){v:=1; v-=1;return webview.eval("document." ++ funcName ++ "('" ++Selector++ "')" ++ this.index ++ childNodesIndex ++ ".options.item(" ++v++ ").text");} getItemCount = function(){var t = webview.eval("document." ++ funcName ++ "('" ++Selector++ "')" ++ this.index ++ childNodesIndex ++ ".options");if type(t)==type.table return ..table.count(t); } 				getName = function() { return this.getProp("name") }; getID = function() { return this.getProp("id") }; getHref = function() { return this.getProp("href") }; getSrc = function() { return this.getProp("src") }; getTag = function() { return this.getProp("tagName") }; getType = function() { return this.getProp("type") }; getClass = function() { return this.getProp("className") }; getStyle = function() { return this.getProp("style") }; setHref = function(v) { return this.setProp("href",v) }; setSrc = function(v) { return this.setProp("src",v) }; setTag = function(v) { return this.setProp("tagName",v) }; setType = function(v) { return this.setProp("type",v) }; setClass = function(v) { return this.setProp("className",v) }; setStyle = function(v) { return this.setProp("style",v) }; byParent = function(){return ..godking.class_func(webview,funcName,Selector,index,childNodes++ this.childIndex ++ ".parentNode",null); }byChildS = function(v){return ..godking.class_func(webview,funcName,Selector,index,childNodes++ this.childIndex ++ ".childNodes",v:1); }focus = function(){webview.doScript("document." ++ funcName ++ "('" ++Selector++ "')" ++ this.index ++ childNodesIndex ++ ".focus()");}byIndex = function(v){if childIndex return ..godking.class_func( webview,funcName,Selector,index,childNodes,v:1); else return ..godking.class_func( webview,funcName,Selector,v:1,childNodes,childIndex); }}class webPageOperation {ctor(webview){}; // 获取对象函数focus = function(){webview.focus();}getProp = function(prop){return webview.eval("document."+prop);}setProp = function(prop,v){if type(v)==type.string v="'"+v+"'";return webview.doScript("document."+prop+"="+v);}hideScrollbar = function(){webview.doScript(`document.body.style.overflow='hidden';document.body.style.overflowX='hidden';document.body.style.overflowY='hidden';document.parentWindow.execScript("document.body.style.overflow='hidden';")`)}hideBoder = function(){webview.doScript("document.body.style.border='0px none #CCCCCC';")}addLimit = function(){webview.doScript(`document.οncοntextmenu=function(){return false;};document.onselectstart=function(){return false;};document.onsdragstart=function(){return false;};`)}getTitle = function(){return webview.eval("document.title");}getCookie = function(){return webview.eval("document.cookie");}	setDesignMode = function(v=true){webview.doScript("document.designMode='"+(v?"on":"off")+"'")}back = function(){webview.doScript("window.history.back();")}forward = function(){webview.doScript("window.history.forward();")}find = function(kv){var fd = function(clss,fd){for(i=1;clss.childNodes().count();1){// 检查当前子对象var curChd = clss.childNodes(i);var is = true;for(k,v in kv){if curChd.getProp(k)!==v {is=false;break;}}if is return curChd; // 如果有子子对象,则深入分析当前子对象if curChd.childNodes().count() {var r = fd(curChd,fd);if r return r; }}			}var cls = this.bySelector("html");if !cls.childNodes().count() cls = this.bySelector("body");if cls.childNodes().count() return fd(cls,fd); }// 创建对象操作类实例函数byID = function(v){ return ..godking.class_func(webview,"getElementById",v) };bySelector = function(v){ return ..godking.class_func(webview,"querySelector",v) };byTagNameS = function(v,index){ return ..godking.class_func(webview,"getElementsByTagName",v,index:1) };byNameS = function(v,index){ return ..godking.class_func(webview,"getElementsByName",v,index:1) };byClassNameS = function(v,index){ return ..godking.class_func(webview,"getElementsByClassName",v,index:1) };bySelectorS = function(v,index){ return ..godking.class_func(webview,"querySelectorAll",v,index:1) };}/**intellisense()
godking.webPageOperation = 网页操作类
godking.webPageOperation( wb ) = 初始化网页操作类。参数:webform、webview、webview2 对象
godking.webPageOperation() = !godking_webPageOperation.
end intellisense**//**intellisense(!godking_webPageOperation.)
byID( "__" ) = 通过ID获取元素对象,创建对象操作集。
bySelector( "__" ) = 通过Selector路径获取元素对象,创建对象操作集。
byTagNameS( "__", 1 ) = 通过TagName获取元素对象集合,创建对象操作集。\n参数1:tagName;参数2:对象索引(从1开始)
byNameS( "__", 1 ) = 通过name获取元素对象集合,创建对象操作集。\n参数1:name;参数2:对象索引(从1开始)
byClassNameS( "__", 1 ) = 通过ClassName获取元素对象集合,创建对象操作集。\n参数1:ClassName;参数2:对象索引(从1开始)
bySelectorS( "__", 1 ) = 通过Selector路径获取元素对象集合,创建对象操作集。\n参数1:Selector路径;参数2:对象索引(从1开始)byID() = !godking_webPageOperation_class.
bySelector() = !godking_webPageOperation_class.
byTagNameS() = !godking_webPageOperation_class.
byNameS() = !godking_webPageOperation_class.
byClassNameS() = !godking_webPageOperation_class.
bySelectorS() = !godking_webPageOperation_class.getProp( "__" ) = 获取属性值。参数:属性名
setProp( "__", ) = 设置属性值。参数:属性名、属性值
hideScrollbar() = 隐藏滚动条
hideBoder() = 隐藏边框
addLimit() = 添加鼠标右键菜单、选择文本、拖拽的限制。
getTitle() = 获取标题
getCookie() = 获取cookie
setDesignMode( true ) = 设置设计模式(编辑模式)
back() = 后退
forward() = 前进
focus() = 网页组件获取输入焦点
end intellisense**//**intellisense(!godking_webPageOperation_class.)
getProp( "__" ) = 获取属性值。参数:属性名
setProp( "__", ) = 设置属性值。参数:属性名、属性值count() = 元素总数量。by开头S结束的函数,可以通过该函数获取总元素数量。
click() = 点击元素
submit() = 提交表单
focus() = 网页元素获取输入焦点getValue() = 取value值
setValue( "__" ) = 置value值getText() = 取value值,自动tostring转文本。
setText( "__" ) = 置value值,自动tostring转文本。getChecked() = 取选中状态
setChecked( true ) = 置选中状态getInnerText() = 取innerText
setInnerText( "__" ) = 置innerTextgetOuterText() = 取outerText
setOuterText( "__" ) = 置outerTextgetOuterHTML() = 取outerHTML
setOuterHTML( "__" ) = 置outerHTMLgetInnerHTML() = 取innerHTML
setInnerHTML( "__" ) = 置innerHTMLbyChildS( 1 ) = 创建子元素对象操作集。参数:子元素索引。
byChildS() = !godking_webPageOperation_class.
byParent() = 创建父元素对象操作集。\n!godking_webPageOperation_class.
byIndex( 1 ) = 创建当前元素集(S结尾的)的指定索引的元素的操作集。参数:元素索引。
byIndex() = !godking_webPageOperation_class.getSelectedItemIndex() = 取选择框当前选中项目索引
setSelectedItemByIndex( __ ) = 置选择框当前选中项目索引
getSelectedItemText() = 取选择框当前选中项目文本
setSelectedItemByText( "__" ) = 置选择框当前选中项目文本
getItemText( __ ) = 取指定项目文本。参数:项目索引(从1开始)
getItemCount() = 取项目数量
getName() = 取name
getID() = 取id
getHref() = 取href
getSrc() = 取src
getTag() = 取tagName
getType() = 取type
getClass() = 取class
getStyle() = 取stylesetHref( "__" ) = 置href
setSrc( "__" ) = 置src
setTag( "__" ) = 置tagName
setType( "__" ) = 置type
setClass( "__" ) = 置class
setStyle( "__" ) = 置styleend intellisense**/

参考

https://blog.csdn.net/sdlgq/article/details/131011599

这篇关于aardio网页组件:webPageOperation的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/490855

相关文章

一文教你Python如何快速精准抓取网页数据

《一文教你Python如何快速精准抓取网页数据》这篇文章主要为大家详细介绍了如何利用Python实现快速精准抓取网页数据,文中的示例代码简洁易懂,具有一定的借鉴价值,有需要的小伙伴可以了解下... 目录1. 准备工作2. 基础爬虫实现3. 高级功能扩展3.1 抓取文章详情3.2 保存数据到文件4. 完整示例

python获取网页表格的多种方法汇总

《python获取网页表格的多种方法汇总》我们在网页上看到很多的表格,如果要获取里面的数据或者转化成其他格式,就需要将表格获取下来并进行整理,在Python中,获取网页表格的方法有多种,下面就跟随小编... 目录1. 使用Pandas的read_html2. 使用BeautifulSoup和pandas3.

Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案

《Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案》:本文主要介绍Vue3组件中getCurrentInstance()获取App实例,但是返回nu... 目录vue3组件中getCurrentInstajavascriptnce()获取App实例,但是返回n

SpringQuartz定时任务核心组件JobDetail与Trigger配置

《SpringQuartz定时任务核心组件JobDetail与Trigger配置》Spring框架与Quartz调度器的集成提供了强大而灵活的定时任务解决方案,本文主要介绍了SpringQuartz定... 目录引言一、Spring Quartz基础架构1.1 核心组件概述1.2 Spring集成优势二、J

使用Python实现获取网页指定内容

《使用Python实现获取网页指定内容》在当今互联网时代,网页数据抓取是一项非常重要的技能,本文将带你从零开始学习如何使用Python获取网页中的指定内容,希望对大家有所帮助... 目录引言1. 网页抓取的基本概念2. python中的网页抓取库3. 安装必要的库4. 发送HTTP请求并获取网页内容5. 解

Vue中组件之间传值的六种方式(完整版)

《Vue中组件之间传值的六种方式(完整版)》组件是vue.js最强大的功能之一,而组件实例的作用域是相互独立的,这就意味着不同组件之间的数据无法相互引用,针对不同的使用场景,如何选择行之有效的通信方式... 目录前言方法一、props/$emit1.父组件向子组件传值2.子组件向父组件传值(通过事件形式)方

Python使用DrissionPage中ChromiumPage进行自动化网页操作

《Python使用DrissionPage中ChromiumPage进行自动化网页操作》DrissionPage作为一款轻量级且功能强大的浏览器自动化库,为开发者提供了丰富的功能支持,本文将使用Dri... 目录前言一、ChromiumPage基础操作1.初始化Drission 和 ChromiumPage

Spring组件初始化扩展点BeanPostProcessor的作用详解

《Spring组件初始化扩展点BeanPostProcessor的作用详解》本文通过实战案例和常见应用场景详细介绍了BeanPostProcessor的使用,并强调了其在Spring扩展中的重要性,感... 目录一、概述二、BeanPostProcessor的作用三、核心方法解析1、postProcessB

kotlin中的行为组件及高级用法

《kotlin中的行为组件及高级用法》Jetpack中的四大行为组件:WorkManager、DataBinding、Coroutines和Lifecycle,分别解决了后台任务调度、数据驱动UI、异... 目录WorkManager工作原理最佳实践Data Binding工作原理进阶技巧Coroutine

Vue项目的甘特图组件之dhtmlx-gantt使用教程和实现效果展示(推荐)

《Vue项目的甘特图组件之dhtmlx-gantt使用教程和实现效果展示(推荐)》文章介绍了如何使用dhtmlx-gantt组件来实现公司的甘特图需求,并提供了一个简单的Vue组件示例,文章还分享了一... 目录一、首先 npm 安装插件二、创建一个vue组件三、业务页面内 引用自定义组件:四、dhtmlx