joetong
playwright chromium could not be successfully closed
def run(playwright, url: str, doc: dict, proxy):
browser = None
try:
browser = playwright.chromium.launch(proxy=proxy)
context = browser.new_context()
context.set_default_navigation_timeout(600000)
# 拦截请求 def block_images_and_css(route, request): if request.resourcetype in ["image", "stylesheet", "script"]: route.abort() else: route.continue()
context.route("*/", block_images_and_css) page = context.new_page() page.goto(url) page.evaluate("window.scrollTo(0, document.body.scrollHeight)") page.wait_for_load_state("domcontentloaded") except Exception as e: print(f"An error occurred: {e}") finally: if browser: browser.close()
# 拦截请求 def block_images_and_css(route, request): if request.resourcetype in ["image", "stylesheet", "script"]: route.abort() else: route.continue()
context.route("*/", block_images_and_css) page = context.new_page() page.goto(url) page.evaluate("window.scrollTo(0, document.body.scrollHeight)") page.wait_for_load_state("domcontentloaded") except Exception as e: print(f"An error occurred: {e}") finally: if browser: browser.close()
6 replies