Container commited on
Commit
aee7417
·
verified ·
1 Parent(s): 7274bf1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -1
app.py CHANGED
@@ -4,10 +4,30 @@ from fastapi import FastAPI, Request
4
  import uvicorn
5
  import time
6
  import json
7
- from urllib.parse import unquote
8
 
9
  app = FastAPI()
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  @app.get("/")
12
  def main():
13
  return {"code": 200,"msg":"Success"}
@@ -40,6 +60,13 @@ def chrome(url:str=None,wait:int=5,header:str=None,cookie:str=None):
40
  if type(cookie) == str:
41
  header_array.update({"cookie":unquote(cookie)})
42
 
 
 
 
 
 
 
 
43
  options = Options()
44
  options.add_argument('--headless')
45
 
 
4
  import uvicorn
5
  import time
6
  import json
7
+ from urllib.parse import unquote, urlparse
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
+ def get_root_domain(url):
16
+ # 解析URL
17
+ parsed_url = urlparse(url)
18
+ # 获取域名部分
19
+ domain = parsed_url.netloc
20
+
21
+ # 分割域名部分以获取根域名
22
+ # 假设根域名是域名的最后两个部分
23
+ parts = domain.split('.')
24
+ if len(parts) > 1:
25
+ # 返回根域名部分
26
+ return '.'.join(parts[-2:])
27
+ else:
28
+ # 如果域名部分少于两个部分,返回整个域名
29
+ return domain
30
+
31
  @app.get("/")
32
  def main():
33
  return {"code": 200,"msg":"Success"}
 
60
  if type(cookie) == str:
61
  header_array.update({"cookie":unquote(cookie)})
62
 
63
+ if 'cookie' in header_array:
64
+ cookie_array = header_array['cookie']
65
+ del header_array['cookie']
66
+ cookie_domain = f'.{get_root_domain(target_url)}'
67
+ for key, value in cookie_array.items():
68
+ driver.execute_script(f'document.cookie = "{key}={value}; path=/; domain={cookie_domain}; expires=Thu, 01 Jan 2050 00:00:00 GMT;');
69
+
70
  options = Options()
71
  options.add_argument('--headless')
72