Container commited on
Commit
973d2bc
·
verified ·
1 Parent(s): 2e32ce9

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +31 -19
main.py CHANGED
@@ -1,25 +1,37 @@
1
  from selenium import webdriver
2
  from selenium.webdriver.chrome.options import Options
 
 
3
 
4
- # 设置无头浏览器选项
5
- options = Options()
6
- options.headless = True
7
 
8
- # 初始化WebDriver
9
- driver = webdriver.Chrome(options=options)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- # 访问网址
12
- driver.get("https://example.com/")
 
13
 
14
- # 网页加载后,Selenium会处理JavaScript代码,包括设置cookie和跳转
15
-
16
- # 您可以检查cookie
17
- cookies = driver.get_cookies()
18
- print(cookies)
19
-
20
- # 您也可以获取当前URL,检查是否发生了跳转
21
- current_url = driver.current_url
22
- print(current_url)
23
-
24
- # 关闭浏览器
25
- driver.quit()
 
1
  from selenium import webdriver
2
  from selenium.webdriver.chrome.options import Options
3
+ from fastapi import FastAPI, Request
4
+ import uvicorn
5
 
6
+ app = FastAPI()
 
 
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__':
35
+ uvicorn.run(app='app:app', host="0.0.0.0", port=7860)
36
+
37