Skip to content

ffreemt/deepl-scraper-pyppeteer

Repository files navigation

deepl-scraper-pp2

[tests]pythonCode style: blackLicense: MITPyPI version

scrape deepl using pyppeteer2 with para info, cross platform (Windows/MacOS/Linux)

Intro

deepl-scraper-pp2 is more or less deepl-scraper-pp. deepl-scraper-pp2 however preserves newlines in the translated text. Hence, it will make life easier when trying to process large chunks of text. deepl-scraper-pp2 is intended for deepl-fastapi2 used in deepl-tr-webui.

Installation

pip install deepl-scraper-pp2
# pip install deepl-scraper-pp2  # upgrade to the latest version

or

poetry add deepl-scraper-pp2
# poetry add deepl-scraper-pp2@latest  # upgrade to the latest version

or clone the repo (git clone https://github.com/ffreemt/deepl-scraper-pyppeteer2.git) and install from it.

Usage

In an ipython session:

# ipython

from deepl_scraper_pp2.deepl_tr import deepl_tr

res = await deepl_tr("test me")
print(res)
# '考我 试探我 测试我 试探'

print(await deepl_tr("test me", to_lang="de"))
# mich testen mich prüfen testen Sie mich

text = "Pyppeteer has almost same API as puppeteer. More APIs are listed in the document"
print(await deepl_tr(text, to_lang="zh"))
# Pyppeteer的API与puppeteer几乎相同。更多的API在文档中列出。

in python

import asyncio
from deepl_scraper_pp2.deepl_tr import deepl_tr

async def main():
    text1 = "test me"
    text2 = "Pyppeteer has almost same API as puppeteer. More APIs are listed in the document"

    coros = [deepl_tr(elm) for elm in [text1, text2]]
    res = await asyncio.gather(*coros, return_exceptions=True)
    print(res)

loop = asyncio.get_event_loop()
try:
    loop.run_until_complete(main())
finally:
    loop.close()

# output: ['考我', 'Pyppeteer的API与puppeteer几乎相同。更多的API在文档中列出']

Disclaimer

The pypi is beta and will likely remain beta -- use it at your own peril.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages