DLL函數及python原生函數調用說明文件
Ø EasySrcipt.dll - 銜接冏rz的指令與用法
Ø ezscript_util.dll - HTML解析的功能
Ø Script.py - Python原生函數,創建自己的函數指令調用
說明 |
冏rz 的指令及用法,銜接 EasyScript 到應用,於腳本中調用此 DLL 檔,即可呼叫類似於 UPL 語法的功能,來處理所需要的運算、搜尋或是編碼的動作 |
函數調用方式 |
sys.path.append(UI.StartupPath+'\Script\Module\dll') clr.AddReferenceToFile("EasyScript.dll") from EasyScript import * EasyScript = EasyScript() |
使用函數指令 |
GetTime() GetDate() FindStrText(來源字串,欲找尋的字串) ReplaceVariable(來源字串,欲取代的字串,欲取代的目的字串) RandomizeNumber(最小值,最大值) RandomizeText(Aanx) StrToBase64(來源字串) StrToMD5(來源字串) Base64Decode(來源字串) SpotStrToVariable(文字串) SaveDataToFile(存放檔案的完整路徑(含檔名),要存的資料,是否先清空檔案後再寫入) LoadFileToVariable(讀取檔案的完整路徑含檔名,讀取指定的行數資料) ConvertBases(來源字串,原來的進制,欲轉換的進制) StrToRegExpEscape(來源字串) Str2Unicode(來源字串) UrlEncodeUnicode(來源字串) Escape(來源字串) UrlDecode(來源字串) Str2UnicodeHTML(來源字串) HtmlDecode(來源字串) FFormat(來源字串,格式) SSplit(來源字串,分割字符,第i項,"CR") GetstrToVariable(來源字串,字串1,字串2,第i個符合項) Matches(來源字串,條件式可代正則表達式) GetMatchCount("欲比對的字串","正則表達式")
#取得 網路卡 的序號 GetMacAddress() #取得 硬碟 的序號 GetHardCode() #取得 CPU 的序號 GetCPUCode() |
備註 |
可參考 call_dll_sample.py 測試檔內範例 |
說明 |
HTML解析的功能,支援html dom和支援xpath,擷取網頁的資料,xpath比regular expression更容易上手,支援jquery selectors |
函數調用方式 |
import clr import sys import System import os
path = os.path.dirname(os.path.abspath(__file__)) + '\\Module\\dll\\' clr.AddReferenceToFileAndPath(path + "ezscript_util.dll") from ezscript_util import * html = "<html><head></head><body><div>div1</div><div class='test'>div2</div></body></html>" hdom = Util.ParseHTML(html) UI.UpdateLog(hdom.SelectSingleNode("//div").InnerText) UI.UpdateLog(hdom.SelectSingleNode("//div[@class=\"test\"]").InnerText) |
使用函數範例 |
# -*- coding: utf-8 -*-
import clr import sys import System import os
try:
path = os.path.dirname(os.path.abspath(__file__)) + '\\Module\\dll\\' clr.AddReferenceToFileAndPath(path + "ezscript_util.dll") from ezscript_util import * hdom=Util.ParseHTML('<html><head></head><body><div>div1</div><div class="classtest">div2</div><div id="idtest">div3</div></body></html>') UI.UpdateLog("XPath div:" + hdom.SelectSingleNode("//div").InnerText) UI.UpdateLog("XPath div class:" + hdom.SelectSingleNode("//div[@class=\"classtest\"]").InnerText) UI.UpdateLog("XPath div id:" + hdom.SelectSingleNode("//div[@id=\"idtest\"]").InnerText) UI.UpdateLog("JQuery div:" + hdom.QuerySelector("div").InnerText) UI.UpdateLog("JQuery div class:" + hdom.QuerySelector("div[class='classtest']").InnerText) UI.UpdateLog("JQuery div id:" + hdom.QuerySelector("#idtest").InnerText) UI.UpdateLog("JQuery div fist:" + hdom.QuerySelector("div:first-child").InnerText) UI.UpdateLog("JQuery div last:" + hdom.QuerySelector("div:last-child").InnerText) for item in hdom.SelectNodes("//div") : UI.UpdateLog("XPath All:" + item.InnerText) for item in hdom.QuerySelectorAll("div") : UI.UpdateLog("JQuery All:" + item.InnerText)
UI.ProceFalse() except Exception as e: UI.UpdateLog('error:' + e.message) UI.ProceFalse()
輸出如下: XPath div:div1 XPath div class:div2 XPath div id:div3 JQuery div:div1 JQuery div class:div2 JQuery div id:div3 JQuery div fist:div1 JQuery div last:div3 XPath All:div1 XPath All:div2 XPath All:div3 JQuery All:div1 JQuery All:div2 JQuery All:div3 |
備註 |
|
說明 |
抓取指定硬碟的序號 |
函數調用方式 |
import clr import sys import System
sys.path.append(UI.StartupPath+'\Script\Module\dll') clr.AddReferenceToFile("HDS.dll") from HDS import * GetID = GetID() |
使用函數範例 |
# -*- coding: utf-8 -*-
import re import clr import sys import System
try: sys.path.append(UI.StartupPath+'\Script\Module\dll') clr.AddReferenceToFile("HDS.dll") from HDS import *
GetID = GetID() UI.UpdateLog(GetID.HdID("C"))
UI.ProceFalse() except Exception as e: UI.UpdateLog(e.message) UI.ProceFalse()
|
備註 |
|
說明 |
Python原生函數,創建自己的函數指令調用 #多行顯示UI.UpdateLog #連結自動添加"^"並自動添加指令到UI.AddShareLink() #網頁解碼(需調用EasyScript.dll), #Matches #Matches2 |
函數調用方式 |
# -*- coding: utf-8 -*- import os
Scriptpath = os.path.abspath('')+'\Script\Module\py\Script.py' Check_Scriptpath = os.path.isfile(Scriptpath) if Check_Scriptpath==False: Scriptpath = os.path.abspath('..\\..\\')+'\Script\Module\py\Script.py' Check_Scriptpath = os.path.isfile(Scriptpath) if Check_Scriptpath==True: execfile(Scriptpath) else: execfile(Scriptpath)
|
使用函數 |
ShareLink(連結1,連結2,連結3,...,連結10) UrlDecode(資料,選擇性參數False) Matches(來源資料,'正則表達式' or "正則表達式",選擇性參數False) Matches2(來源資料,'正則表達式' or "正則表達式",選擇性參數False)
多行顯示UI.UpdateLog 選擇性參數一定要放在最後面 Logs(變數1,變數2,變數3,...,變數n,選擇性參數":0" or ":1" or ":2" or ":3" or ":4") |
備註 |
可參考 Script.py |