MCPcopy Create free account
hub / github.com/a943512/PyAibote / CustomWebScript

Class CustomWebScript

test_web.py:9–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7# 2. 自定义一个脚本类,继承 WebBotMain
8# 2. Customize a script class and inherit WebBotMain
9class CustomWebScript(WebBotMain):
10
11 # 3. 设置是否终端打印输出 DEBUG :输出, INFO :不输出, 默认打印输出
12 # 3. Set whether the terminal prints output DEBUG: output, INFO: no output, and print output by default
13 Log_Level = "DEBUG"
14 Websocket_Log_Level = "DEBUG"
15
16
17 # 4. 终端打印信息是否存储LOG文件 True: 储存, False:不存储
18 # 4. Does the terminal print information store the LOG file? True: yes, False: no
19 Log_Storage = True # True
20
21
22 # 5. 全局隐式等待 [找不到元素重复查找]
23 # 5. Global implicit wait [repeated search of element not found]
24 # 5.1 元素未加载等待时间(秒)
25 # 5.1 element not loaded wait time (seconds)
26 Implicit_Waiting = 5
27
28 # 5.2 元素未加载间隔多少时间重复加载(秒)
29 # 5.2 How often does the element load repeatedly (seconds)
30 Implicit_Waiting_Frequency = 0.5
31
32 # 5.3 超过未加载等待时间是否抛出异常
33 # 5.3 Whether to throw an exception when the waiting time for unloading exceeds
34 Implicit_Waiting_Throwing = False
35
36
37 # 6. 注意:此方法是脚本执行入口
38 # 6. Note: This method is a script execution portal.
39 def script_main(self):
40
41 result = self.goto("https://baidu.com")
42 print(result)
43 result = self.get_extend_param()
44 result = eval(result)
45 print(type(result))
46 # 6.1. 显示等待和隐式等待意思一样, 显示等待可以让你在某个局部代码中自定义设置等待时长
47 # 6.1. Displaying waiting means the same as implicit waiting. Displaying waiting allows you to customize the waiting time in a local code.
48 # StartShowWait函数后的代码按照等待10秒,每个0.5秒重复加载,False找不到不抛出异常,此时你如果设置的全局隐式等待将不生效直到结束显示等待
49 # StartShowWait function is loaded repeatedly every 0.5 seconds according to the waiting time of 10 seconds. If False is not found, no exception will be thrown. At this time, if you set the global implicit waiting, it will not take effect until the display waiting is over
50 self.StartShowWait(10, 0.5, False)
51
52 result = self.goto("https://qq.com")
53 print(result)
54 result = self.goto("https://www.hao123.com")
55 print(result)
56
57 # 6.1 结束显示等待,也是自定义结束局部等待此时如果设置的全局隐式等待后面的代码将按全局隐式等待的设置来执行
58 # 6.1 Ending display waiting is also a custom ending local waiting. At this time, if the global implicit waiting is set, the code behind it will be executed according to the setting of global implicit waiting
59 self.EndShowWait()
60
61
62
63
64 # 主函数死循环时web驱动连接断开异常捕获跳出死循环demo示例代码
65 # while True:
66 # try:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected