Container commited on
Commit
247ee08
·
verified ·
1 Parent(s): 3895bea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -18
app.py CHANGED
@@ -14,34 +14,32 @@ def main():
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"}
25
 
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
 
 
14
 
15
  @app.get("/chrome")
16
  def chrome(url:str=None,wait:int=5,header:str=None,cookie:str=None):
 
 
 
 
 
17
 
18
+ # 必须有目标url
19
+ if type(url) == str:
20
+ target_url = unquote(url)
21
+ else:
22
  return {"code": 500,"msg":"No target URL"}
23
 
24
+ # 等待时间必须在 0 30 之间
25
+ if wait_time in range(0, 31):
26
+ wait_time = wait
27
+ else:
28
  return {"code": 500,"msg":"The waiting time must be between 0 and 30"}
29
 
30
  header_array = {}
31
+
32
+ # header可以覆写,但必须传入json
33
  try:
34
+ if type(header) == str:
35
+ header_array.update(json.loads(unquote(header)))
 
 
 
36
  except Exception as e:
37
  return {"code": 500,"msg":"The header field is not JSON"}
38
+
39
+ # 如果输入了cookie
40
+ if type(cookie) == str:
41
+ header_array.update({"cookie":unquote(cookie)})
42
 
 
 
 
 
 
43
  options = Options()
44
  options.add_argument('--headless')
45