Selenium-Script / app.py
Container's picture
Update app.py
5b38230 verified
raw
history blame
1.23 kB
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import WebDriverException, TimeoutException
from fastapi import FastAPI, Request
import uvicorn
import time
app = FastAPI()
@app.get("/")
def main():
target_url = 'https://test5.container-z.art/test26'
wait_time = 10
options = Options()
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)
driver.get(target_url)
time.sleep(wait_time)
# 获取当前URL
current_url = driver.current_url
# 获取页面源代码
page_source = driver.page_source
# 获取cookie
cookies = driver.get_cookies()
# 是否有跳转过
is_jump = (target_url != current_url)
data = {
"url": current_url,
"page_source": page_source,
"cookies": cookies,
"is_jump": is_jump
}
driver.quit()
return {"code": 200,"data":data}
if __name__ == '__main__':
uvicorn.run(app='app:app', host="0.0.0.0", port=7860)