Spaces:
Build error
Build error
| from selenium import webdriver | |
| from selenium.webdriver.chrome.options import Options | |
| from fastapi import FastAPI, Request | |
| import uvicorn | |
| app = FastAPI() | |
| def main(): | |
| # 设置无头浏览器选项 | |
| options = Options() | |
| options.headless = True | |
| # 初始化WebDriver | |
| driver = webdriver.Chrome(options=options) | |
| # 访问网址 | |
| driver.get("https://example.com/") | |
| # 网页加载后,Selenium会处理JavaScript代码,包括设置cookie和跳转 | |
| # 您可以检查cookie | |
| cookies = driver.get_cookies() | |
| print(cookies) | |
| # 您也可以获取当前URL,检查是否发生了跳转 | |
| current_url = driver.current_url | |
| print(current_url) | |
| # 关闭浏览器 | |
| driver.quit() | |
| return {"code": 200,"msg":"Success"} | |
| if __name__ == '__main__': | |
| uvicorn.run(app='app:app', host="0.0.0.0", port=7860) | |