Skip to content

Instantly share code, notes, and snippets.

@RedmondLee
Created February 21, 2024 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RedmondLee/ec0c13215c97c9902cd8c12ecbfbca1c to your computer and use it in GitHub Desktop.
Save RedmondLee/ec0c13215c97c9902cd8c12ecbfbca1c to your computer and use it in GitHub Desktop.
block.py
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