Spaces:
Build error
Build error
Update main.py
Browse files
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 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|