Container commited on
Commit
65230b0
·
verified ·
1 Parent(s): 8b65705

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -14
app.py CHANGED
@@ -1,4 +1,3 @@
1
- # from selenium import webdriver
2
  from seleniumwire import webdriver
3
  from selenium.webdriver.chrome.options import Options
4
  from fastapi import FastAPI, Request
@@ -8,27 +7,37 @@ import json
8
 
9
  app = FastAPI()
10
 
11
- def convert_cookies_to_dict(cookies):
12
- cookies = dict([l.split("=", 1) for l in cookies.split("; ")])
13
- return cookies
14
-
15
  @app.get("/")
16
  def main():
17
- target_url = 'https://test5.container-z.art/test26'
18
- wait_time = 10
19
- header_list = '{"user-agent": "New York","cookie": "_zap=386b2646-cd4f-48b0-831c-0f4e0fcb84d; d_c0=ATBVpddW2hePTs-uWJUqnuikOgCLTtzDaQ=|1702569488; _xsrf=9Exea3EejXTsAZewjRCns4TPklsjdCpV; __zse_ck=001_xCDDL0hUsjpAaMgmQE7pCfeU+zXi0/T+YTGbyY=OkkWy54lHQjmO1If3BOBMUzDjeY=d26WyAD5j0BG=m7jR7RrpRqv2ImjXDfJPzUEzARb4/TImweWRybZ5aGbVke4B; BEC=9f6899d2c0337126a73fd6e01ed7c740; gdxidpyhxdE=tfBS35OO12TxVYkb6i%5Ce7mQekmAMzv2e1Ah%5CGS4h%5CwU7xS47p9%2Fd4T%5CNEmx7s%2Bu%2Fr8mkLktUMVIPQ404Z1OxrejYyRQ3aSgLL7CBsT2nRhTXpzWaxqr7KyuaHSCMZjsK6OBaCM5GsMTSor4baQvmzWfo5SZqccCgWZTrn4Ii2tgDNH0w%3A1718799277544"}'
20
-
21
- header_array = json.loads(header_list)
22
- # cookies = convert_cookies_to_dict(cookies_string)
23
 
 
 
 
 
 
 
 
24
  options = Options()
25
  options.add_argument('--headless')
26
- # for key, value in header_array.items():
27
- # options.add_argument(f'{key}="{value}"')
28
 
29
  driver = webdriver.Chrome(options=options)
30
 
31
- driver.header_overrides = header_array
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  driver.get(target_url)
34
 
 
 
1
  from seleniumwire import webdriver
2
  from selenium.webdriver.chrome.options import Options
3
  from fastapi import FastAPI, Request
 
7
 
8
  app = FastAPI()
9
 
 
 
 
 
10
  @app.get("/")
11
  def main():
12
+ return {"code": 200,"msg":"Success"}
13
+
14
+ @app.get("/chrome")
15
+ def chrome(url:str=None,wait:int=5,header:str=None):
 
 
16
 
17
+ target_url = url
18
+ wait_time = wait
19
+ header_list = header
20
+
21
+ if target_url == None:
22
+ return {"code": 500,"msg":"No target URL"}
23
+
24
  options = Options()
25
  options.add_argument('--headless')
 
 
26
 
27
  driver = webdriver.Chrome(options=options)
28
 
29
+ try:
30
+ if header_list == None:
31
+ pass
32
+ else:
33
+ header_array = json.loads(header_list)
34
+ driver.header_overrides = header_array
35
+ except ValueError:
36
+ driver.quit()
37
+ return {"code": 500,"msg":"The header field is not JSON"}
38
+ except Exception as e:
39
+ driver.quit()
40
+ return {"code": 500,"msg":"Unable to overwrite header"}
41
 
42
  driver.get(target_url)
43