2025年6月1日星期日

playwright将网页截图的方式

 from playwright.async_api import async_playwright

import os

import pytesseract
from PIL import Image
import asyncio


proxy = 'http://abc.com.cn:80'

async def download():
    async with async_playwright() as p:
        cookie = os.path.join(cookies_folder, "cookie.json")
        browser = await p.chromium.launch(
            headless=False,
            channel="chrome",
            proxy={"server": proxy}  # 设置代理?
        )
        context = await browser.new_context()
        page = await context.new_page()
        await page.goto("https://ddd.com/", timeout=180000)
        await page.wait_for_load_state("networkidle")
        # screenshot_path = 'fullpage.png'
        # await page.screenshot(path=screenshot_path, full_page=True)
        shadow_host = await page.query_selector('div#transcend-consent-manager')
        await shadow_host.screenshot(path='shadow_host.png')


        image = Image.open('shadow_host.png')
        data = pytesseract.image_to_data(image, lang='chi_sim+eng', output_type=pytesseract.Output.DICT)

没有评论:

发表评论

小型网站的ubuntu服务器如何提升连接数

 当服务器有多个api应用,或者网站的时候,会出现网页打不开。但是cpu、内存等都很空闲。这种情况,有可能是网站的文件数设置不正确。 查询服务器支持的TCP连接数: ulimit -n 默认是1024 需要增加方法: 编辑/etc/security/limits.conf * s...