1
- from selenium import webdriver
2
1
from selenium .common import exceptions
3
- from selenium .webdriver .chrome import options
4
2
from selenium .webdriver .common .by import By
5
- from selenium .webdriver .chrome .service import Service
6
3
from random import randint
7
4
from random import normalvariate
8
5
import requests
12
9
import re
13
10
14
11
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
+
15
35
def send_wechat (user_index , msg ):
16
36
"""Send messeage to WeChat"""
17
37
wechat_url = 'http://wxpusher.zjiecode.com/api/send/message/'
@@ -26,20 +46,19 @@ def report(user_index, try_times):
26
46
today = time .localtime (time .time ())
27
47
print ('[Info]' , 'Now:' , time .asctime (today ))
28
48
29
- chrome_options = options .Options ()
49
+ browser_options = options .Options ()
30
50
if config .browser_path != 'auto' :
31
- chrome_options .binary_location = config .browser_path
51
+ browser_options .binary_location = config .browser_path
32
52
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' )
35
55
36
56
print ('[Info] Launching Browser' )
37
57
if (config .driver_path != 'auto' ):
38
58
service = Service (config .driver_path )
39
- browser = webdriver .Chrome (
40
- service = service , options = chrome_options )
59
+ browser = Browser (service = service , options = browser_options )
41
60
else :
42
- browser = webdriver . Chrome (options = chrome_options )
61
+ browser = Browser (options = browser_options )
43
62
44
63
browser .set_window_size (480 , 720 )
45
64
@@ -207,6 +226,8 @@ def report(user_index, try_times):
207
226
208
227
def run ():
209
228
print ('[Info] Task started\n ' )
229
+ import_browser (config .browser_type )
230
+ print ()
210
231
211
232
for user_index in range (len (config .users )):
212
233
print ('[Info] Reporting for user ' + str (user_index + 1 ), end = ', ' )
0 commit comments