Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,27 +7,17 @@ app = FastAPI()
|
|
| 7 |
|
| 8 |
@app.get("/")
|
| 9 |
def main():
|
| 10 |
-
# 设置无头浏览器选项
|
| 11 |
options = Options()
|
| 12 |
-
options.headless
|
| 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 |
|
|
|
|
| 7 |
|
| 8 |
@app.get("/")
|
| 9 |
def main():
|
|
|
|
| 10 |
options = Options()
|
| 11 |
+
options.add_argument('--headless')
|
|
|
|
|
|
|
| 12 |
driver = webdriver.Chrome(options=options)
|
| 13 |
+
driver.get('https://example.com/')
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
cookies = driver.get_cookies()
|
| 16 |
print(cookies)
|
| 17 |
|
|
|
|
| 18 |
current_url = driver.current_url
|
| 19 |
print(current_url)
|
| 20 |
|
|
|
|
| 21 |
driver.quit()
|
| 22 |
return {"code": 200,"msg":"Success"}
|
| 23 |
|