Skip to content

Commit 5d074eb

Browse files
committed
Added support for Firefox and Edge
1 parent 4c9582e commit 5d074eb

File tree

4 files changed

+51
-11
lines changed

4 files changed

+51
-11
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Auto daily reporter for SSPU HSM
44

55
Support WeChat push, multi-user, scheduled auto report
66

7+
Support Google Chrome, Firefox, Microsoft Edge
8+
79
[English](README.md) | [中文](README_zh-cn.md)
810

911
## Quick Start

README_zh-cn.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
支持**微信推送报送结果****多用户****定时自动报送**
66

7+
支持 Google Chrome, Firefox, Microsoft Edge
8+
79
体温在用户定义的区间内使用正态分布随机生成。
810

911
[English](README.md) | [中文](README_zh-cn.md)
@@ -32,6 +34,18 @@
3234

3335
下载 ChromeDriver 后,你需要将可执行文件所在的目录加入 `PATH` 环境变量中。你也可以跳过此步,但如果跳过此步,你需要将 ChromeDriver 可执行文件的路径写入 `config.py` 中。
3436

37+
## 如果你不使用 Google Chrome
38+
39+
除 Google Chrome 外,本工具也支持 Firefox 和 Microsoft Edge。你只需要安装相应版本的 `msedgedriver` (适用于 Microsoft Edge) 或 `geckodriver` (适用于 Firefox),并把 `config.py` 中的 `browser_type` 修改为相应的浏览器即可。
40+
41+
`browser_type` 可选项:
42+
43+
- `chrome`
44+
- `firefox`
45+
- `edge`
46+
47+
如果有必要,你还可以手动指定 `driver_path``browser_path`
48+
3549
## 安装 Python
3650

3751
[下载](https://www.python.org/downloads/)并安装 `Python 3.x`

config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
timeout = 120
55
retry_times = 20
66

7+
browser_type = 'chrome'
8+
# support: chrome edge firefox
9+
710
driver_path = 'auto'
811
browser_path = 'auto'
912
headless = False
1013

1114
app_token = 'AT_ABCDEF0123456789abcdef0123456789'
12-
# app_token = None if do not use WeChat push
15+
# app_token = None, if do not use WeChat push
1316

1417
report_times = [
1518
'00:30',

daily_reporter.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
from selenium import webdriver
21
from selenium.common import exceptions
3-
from selenium.webdriver.chrome import options
42
from selenium.webdriver.common.by import By
5-
from selenium.webdriver.chrome.service import Service
63
from random import randint
74
from random import normalvariate
85
import requests
@@ -12,6 +9,29 @@
129
import re
1310

1411

12+
def import_browser(browser_type: str):
13+
global options, Service, Browser
14+
if browser_type == 'chrome':
15+
print('[Info]', 'Using browser: Chrome')
16+
from selenium.webdriver.chrome import options
17+
from selenium.webdriver.chrome.service import Service
18+
from selenium.webdriver import Chrome as Browser
19+
elif browser_type == 'firefox':
20+
print('[Info]', 'Using browser: Firefox')
21+
from selenium.webdriver.firefox import options
22+
from selenium.webdriver.firefox.service import Service
23+
from selenium.webdriver import Firefox as Browser
24+
elif browser_type == 'edge':
25+
print('[Info]', 'Using browser: Edge')
26+
from selenium.webdriver.edge import options
27+
from selenium.webdriver.edge.service import Service
28+
from selenium.webdriver import Edge as Browser
29+
else:
30+
print('[Error] Unsupported browser type')
31+
print('[Error] Stopping')
32+
exit(1)
33+
34+
1535
def send_wechat(user_index, msg):
1636
"""Send messeage to WeChat"""
1737
wechat_url = 'http://wxpusher.zjiecode.com/api/send/message/'
@@ -26,20 +46,19 @@ def report(user_index, try_times):
2646
today = time.localtime(time.time())
2747
print('[Info]', 'Now:', time.asctime(today))
2848

29-
chrome_options = options.Options()
49+
browser_options = options.Options()
3050
if config.browser_path != 'auto':
31-
chrome_options.binary_location = config.browser_path
51+
browser_options.binary_location = config.browser_path
3252
if config.headless:
33-
chrome_options.add_argument('--headless')
34-
chrome_options.add_argument('--disable-gpu')
53+
browser_options.add_argument('--headless')
54+
browser_options.add_argument('--disable-gpu')
3555

3656
print('[Info] Launching Browser')
3757
if (config.driver_path != 'auto'):
3858
service = Service(config.driver_path)
39-
browser = webdriver.Chrome(
40-
service=service, options=chrome_options)
59+
browser = Browser(service=service, options=browser_options)
4160
else:
42-
browser = webdriver.Chrome(options=chrome_options)
61+
browser = Browser(options=browser_options)
4362

4463
browser.set_window_size(480, 720)
4564

@@ -207,6 +226,8 @@ def report(user_index, try_times):
207226

208227
def run():
209228
print('[Info] Task started\n')
229+
import_browser(config.browser_type)
230+
print()
210231

211232
for user_index in range(len(config.users)):
212233
print('[Info] Reporting for user ' + str(user_index + 1), end=', ')

0 commit comments

Comments
 (0)