Container commited on
Commit
494cdcf
·
verified ·
1 Parent(s): 3b401c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  from fastapi import FastAPI, Request
2
  import uvicorn
3
 
@@ -5,6 +7,28 @@ app = FastAPI()
5
 
6
  @app.get("/")
7
  def main():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  return {"code": 200,"msg":"Success"}
9
 
10
  if __name__ == '__main__':
 
1
+ from selenium import webdriver
2
+ from selenium.webdriver.chrome.options import Options
3
  from fastapi import FastAPI, Request
4
  import uvicorn
5
 
 
7
 
8
  @app.get("/")
9
  def main():
10
+ # 设置无头浏览器选项
11
+ options = Options()
12
+ options.headless = True
13
+
14
+ # 初始化WebDriver
15
+ driver = webdriver.Chrome(options=options)
16
+
17
+ # 访问网址
18
+ driver.get("https://example.com/")
19
+
20
+ # 网页加载后,Selenium会处理JavaScript代码,包括设置cookie和跳转
21
+
22
+ # 您可以检查cookie
23
+ cookies = driver.get_cookies()
24
+ print(cookies)
25
+
26
+ # 您也可以获取当前URL,检查是否发生了跳转
27
+ current_url = driver.current_url
28
+ print(current_url)
29
+
30
+ # 关闭浏览器
31
+ driver.quit()
32
  return {"code": 200,"msg":"Success"}
33
 
34
  if __name__ == '__main__':