Container commited on
Commit
5b38230
·
verified ·
1 Parent(s): ca11d6d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -7
app.py CHANGED
@@ -12,22 +12,37 @@ app = FastAPI()
12
 
13
  @app.get("/")
14
  def main():
 
 
 
15
  options = Options()
16
  options.add_argument('--headless')
17
  driver = webdriver.Chrome(options=options)
18
- driver.get('https://test5.container-z.art/test26')
 
 
19
 
20
- # WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, "body")))
21
- time.sleep(10)
22
 
 
 
 
 
23
  cookies = driver.get_cookies()
24
- print(cookies)
 
 
25
 
26
- current_url = driver.current_url
27
- print(current_url)
 
 
 
 
28
 
29
  driver.quit()
30
- return {"code": 200,"msg":"Success"}
31
 
32
  if __name__ == '__main__':
33
  uvicorn.run(app='app:app', host="0.0.0.0", port=7860)
 
12
 
13
  @app.get("/")
14
  def main():
15
+ target_url = 'https://test5.container-z.art/test26'
16
+ wait_time = 10
17
+
18
  options = Options()
19
  options.add_argument('--headless')
20
  driver = webdriver.Chrome(options=options)
21
+ driver.get(target_url)
22
+
23
+ time.sleep(wait_time)
24
 
25
+ # 获取当前URL
26
+ current_url = driver.current_url
27
 
28
+ # 获取页面源代码
29
+ page_source = driver.page_source
30
+
31
+ # 获取cookie
32
  cookies = driver.get_cookies()
33
+
34
+ # 是否有跳转过
35
+ is_jump = (target_url != current_url)
36
 
37
+ data = {
38
+ "url": current_url,
39
+ "page_source": page_source,
40
+ "cookies": cookies,
41
+ "is_jump": is_jump
42
+ }
43
 
44
  driver.quit()
45
+ return {"code": 200,"data":data}
46
 
47
  if __name__ == '__main__':
48
  uvicorn.run(app='app:app', host="0.0.0.0", port=7860)