Spaces:
Build error
Build error
Update app.py
Browse files
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 |
-
|
18 |
-
|
19 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|