Skip to main content

Typed Python wrapper for Phantomjs Cloud API

Project description

Code style: black

PhantomBrowser is typed Python wrapper for phantomjscloud.com api with optimize magic rendering and support asynchronous.

Installation

pip install phantombrowser

Example

render html:

from PhantomBrowser import Browser


browser = Browser()
response = browser.get("https://example.com")
print(response.text)
browser.close()

render plain text:

from PhantomBrowser import Browser


browser = Browser()
response = browser.get("https://example.com", render="plainText")
print(response.text)
browser.close()

render image:

from PhantomBrowser import Browser


browser = Browser()
response = browser.get("https://example.com", render="png")
browser.saveAs("example.png", response.content)
browser.close()

render PDF:

from PhantomBrowser import Browser


browser = Browser()
response = browser.get("https://example.com", render="pdf")
browser.saveAs("example.pdf", response.content)
browser.close()

the other method like browser.post(), browser.put(), browser.patch(), browser.option() and browser.delete() also supported.

You can also use the API key by setting the environment variable PHANTOMJSCLOUD.COM_APIKEY or directly in the class

from PhantomBrowser import Browser


browser = Browser("Your API Key")

Asynchronous Example

from PhantomBrowser import AsyncBrowser
import asyncio


async def main():
    browser = AsyncBrowser()
    response = await browser.get("https://example.com")
    print(await response.text())
    await browser.close()

if __name__ == '__main__':
    asyncio.run(main())

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

phantombrowser-0.0.1.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

phantombrowser-0.0.1-py2.py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page