-
-
Save RedmondLee/ec0c13215c97c9902cd8c12ecbfbca1c to your computer and use it in GitHub Desktop.
block.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import asyncio | |
import fastapi | |
import uvicorn | |
from loguru import logger | |
from threading import Thread, Event | |
app = fastapi.FastAPI() | |
started = Event() | |
def test(): | |
started.wait() | |
time.sleep(1) | |
from DrissionPage import ChromiumPage | |
page = ChromiumPage() | |
page.get('http://127.0.0.1:2333/') | |
logger.debug('page.get') | |
page.wait.load_start(timeout=5) | |
logger.debug('page.wait.end') | |
text = page.handle_alert(accept=True) | |
logger.debug(['Text:', text]) | |
@app.on_event("startup") | |
async def on_startup(): | |
started.set() | |
@app.get("/") | |
async def read_root(): | |
await asyncio.sleep(0.5) | |
html = '''<script>alert("helloworld")</script>''' | |
return fastapi.responses.HTMLResponse(content=html) | |
if __name__ == "__main__": | |
Thread(target=test).start() | |
uvicorn.run(app, host='127.0.0.1', port=2333) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment