Container commited on
Commit
3895bea
·
verified ·
1 Parent(s): 7ff1c8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -13,11 +13,12 @@ def main():
13
  return {"code": 200,"msg":"Success"}
14
 
15
  @app.get("/chrome")
16
- def chrome(url:str=None,wait:int=5,header:str=None):
17
 
18
  target_url = url
19
  wait_time = wait
20
  header_list = header
 
21
 
22
  if target_url == None:
23
  return {"code": 500,"msg":"No target URL"}
@@ -25,24 +26,28 @@ def chrome(url:str=None,wait:int=5,header:str=None):
25
  if wait_time not in range(0, 31):
26
  return {"code": 500,"msg":"The waiting time must be between 0 and 30"}
27
 
28
- options = Options()
29
- options.add_argument('--headless')
30
 
31
- driver = webdriver.Chrome(options=options)
32
-
33
  try:
34
  if header_list == None:
35
  pass
36
  else:
37
  # print(unquote(header_list))
38
- header_array = json.loads(unquote(header_list))
39
- driver.header_overrides = header_array
40
- except ValueError:
41
- driver.quit()
42
- return {"code": 500,"msg":"The header field is not JSON"}
43
  except Exception as e:
44
- driver.quit()
45
- return {"code": 500,"msg":"Unable to overwrite header"}
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  driver.get(target_url)
48
 
 
13
  return {"code": 200,"msg":"Success"}
14
 
15
  @app.get("/chrome")
16
+ def chrome(url:str=None,wait:int=5,header:str=None,cookie:str=None):
17
 
18
  target_url = url
19
  wait_time = wait
20
  header_list = header
21
+ cookie_string = cookie
22
 
23
  if target_url == None:
24
  return {"code": 500,"msg":"No target URL"}
 
26
  if wait_time not in range(0, 31):
27
  return {"code": 500,"msg":"The waiting time must be between 0 and 30"}
28
 
29
+ header_array = {}
 
30
 
 
 
31
  try:
32
  if header_list == None:
33
  pass
34
  else:
35
  # print(unquote(header_list))
36
+ header_array.update(json.loads(unquote(header_list)))
 
 
 
 
37
  except Exception as e:
38
+ return {"code": 500,"msg":"The header field is not JSON"}
39
+
40
+ if cookie_string == None:
41
+ pass
42
+ else:
43
+ header_array.update({"cookie":cookie_string})
44
+
45
+ options = Options()
46
+ options.add_argument('--headless')
47
+
48
+ driver = webdriver.Chrome(options=options)
49
+
50
+ driver.header_overrides = header_array
51
 
52
  driver.get(target_url)
53