https://registry.npmmirror.com/binary.html?path=chromium-browser-snapshots/Win_x64/
手动下载安装包
修改文件
C:\Users\luyan\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyppeteer\chromium_downloader.py
# 修改这段代码
def download_chromium() -> None:
"""Download and extract chromium."""
file = "C:/Users/luyan/Downloads/chrome-win.zip"
with open(file, "rb") as fp:
bytes = BytesIO(fp.read())
extract_zip(bytes, DOWNLOADS_FOLDER / REVISION)
#extract_zip(download_zip(get_url()), DOWNLOADS_FOLDER / REVISION)
index.py
import asyncio
from pyppeteer import launch
async def main(text, sl, tl):
browser = await launch()
page = await browser.newPage()
await page.goto('http://translate.google.com/?sl='+ sl +'&tl='+ tl +'&text='+ text +'&op=translate')
bodyHandle = await page.J('.ryNqvb');
result = await page.evaluate('body => body.innerHTML', bodyHandle)
print(result)
await browser.close()
asyncio.run(main('Hello, world!', 'auto', 'zh-CN'))