Container commited on
Commit
06ff70d
·
verified ·
1 Parent(s): 4f23774

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -50
app.py CHANGED
@@ -11,60 +11,49 @@ import json
11
 
12
  app = FastAPI()
13
 
14
- def convert_cookies_to_dict(cookies):
15
- cookies = dict([l.split("=", 1) for l in cookies.split("; ")])
16
- return cookies
17
-
18
  @app.get("/")
19
  def main():
20
  target_url = 'https://test5.container-z.art/test26'
21
  wait_time = 10
22
- header_list = '{"name": "John", "age": 30, "user-agent": "New York"}'
23
- mode = "get"
24
- cookies_string = "_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"
25
-
26
- header_array = json.loads(header_list)
27
- cookies = convert_cookies_to_dict(cookies_string)
28
-
29
- options = Options()
30
- options.add_argument('--headless')
31
- # options.add_argument('--disable-gpu')
32
- # options.add_argument("no-sandbox")
33
- # options.add_argument("--disable-extensions")
34
- for key, value in header_array.items():
35
- options.add_argument(f'{key}="{value}"')
36
-
37
- driver = webdriver.Chrome(options=options)
38
- print(cookies)
39
- # driver.add_cookie(cookies)
40
-
41
- driver.get(target_url)
42
-
43
- print(driver.page_source)
44
-
45
- time.sleep(wait_time)
46
-
47
- # 获取当前URL
48
- current_url = driver.current_url
49
-
50
- # 获取页面源代码
51
- page_source = driver.page_source
52
-
53
- # 获取cookie
54
- cookies = driver.get_cookies()
55
-
56
- # 是否有跳转过
57
- is_jump = (target_url != current_url)
58
-
59
- data = {
60
- "url": current_url,
61
- "page_source": page_source,
62
- "cookies": cookies,
63
- "is_jump": is_jump
64
- }
65
-
66
- driver.quit()
67
- return {"code": 200,"data":data}
68
 
69
  if __name__ == '__main__':
70
  uvicorn.run(app='app:app', host="0.0.0.0", port=7860)
 
11
 
12
  app = FastAPI()
13
 
 
 
 
 
14
  @app.get("/")
15
  def main():
16
  target_url = 'https://test5.container-z.art/test26'
17
  wait_time = 10
18
+ header_list = '{"name": "John", "age": 30, "User-Agent": "New York"}'
19
+
20
+ try:
21
+ options = Options()
22
+ options.add_argument('--headless')
23
+
24
+ header_array = json.loads(header_list)
25
+
26
+
27
+ driver = webdriver.Chrome(options=options)
28
+ driver.get(target_url)
29
+
30
+ print(driver.page_source)
31
+
32
+ time.sleep(wait_time)
33
+
34
+ # 获取当前URL
35
+ current_url = driver.current_url
36
+
37
+ # 获取页面源代码
38
+ page_source = driver.page_source
39
+
40
+ # 获取cookie
41
+ cookies = driver.get_cookies()
42
+
43
+ # 是否有跳转过
44
+ is_jump = (target_url != current_url)
45
+
46
+ data = {
47
+ "url": current_url,
48
+ "page_source": page_source,
49
+ "cookies": cookies,
50
+ "is_jump": is_jump
51
+ }
52
+
53
+ driver.quit()
54
+ return {"code": 200,"data":data}
55
+ except Exception as e:
56
+ return {"code": 500,"msg":e}
 
 
 
 
 
 
 
57
 
58
  if __name__ == '__main__':
59
  uvicorn.run(app='app:app', host="0.0.0.0", port=7860)