Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,6 +38,7 @@ def chrome(url:str=None,wait:int=5,header:str=None,cookie:str=None):
|
|
| 38 |
# 必须有目标url
|
| 39 |
if type(url) == str:
|
| 40 |
target_url = unquote(url)
|
|
|
|
| 41 |
else:
|
| 42 |
return {"code": 500,"msg":"No target URL"}
|
| 43 |
|
|
@@ -60,19 +61,21 @@ def chrome(url:str=None,wait:int=5,header:str=None,cookie:str=None):
|
|
| 60 |
if type(cookie) == str:
|
| 61 |
header_array.update({"cookie":unquote(cookie)})
|
| 62 |
|
|
|
|
|
|
|
| 63 |
options = Options()
|
| 64 |
options.add_argument('--headless')
|
| 65 |
|
| 66 |
driver = webdriver.Chrome(options=options)
|
| 67 |
|
|
|
|
|
|
|
| 68 |
if 'cookie' in header_array:
|
| 69 |
cookie_array = convert_cookies_to_dict(header_array['cookie'])
|
| 70 |
del header_array['cookie']
|
| 71 |
-
cookie_domain = f'.{get_root_domain(target_url)}'
|
| 72 |
for key, value in cookie_array.items():
|
| 73 |
-
driver.
|
| 74 |
-
|
| 75 |
-
|
| 76 |
driver.header_overrides = header_array
|
| 77 |
|
| 78 |
driver.get(target_url)
|
|
|
|
| 38 |
# 必须有目标url
|
| 39 |
if type(url) == str:
|
| 40 |
target_url = unquote(url)
|
| 41 |
+
target_domain = get_root_domain(target_url)
|
| 42 |
else:
|
| 43 |
return {"code": 500,"msg":"No target URL"}
|
| 44 |
|
|
|
|
| 61 |
if type(cookie) == str:
|
| 62 |
header_array.update({"cookie":unquote(cookie)})
|
| 63 |
|
| 64 |
+
|
| 65 |
+
|
| 66 |
options = Options()
|
| 67 |
options.add_argument('--headless')
|
| 68 |
|
| 69 |
driver = webdriver.Chrome(options=options)
|
| 70 |
|
| 71 |
+
driver.get(target_domain)
|
| 72 |
+
|
| 73 |
if 'cookie' in header_array:
|
| 74 |
cookie_array = convert_cookies_to_dict(header_array['cookie'])
|
| 75 |
del header_array['cookie']
|
|
|
|
| 76 |
for key, value in cookie_array.items():
|
| 77 |
+
driver.add_cookie({"name": key, "value": value, "domain": f'.{target_domain}', "path": "/"})
|
| 78 |
+
|
|
|
|
| 79 |
driver.header_overrides = header_array
|
| 80 |
|
| 81 |
driver.get(target_url)
|