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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 2 Python 3

File details

Details for the file phantombrowser-0.0.1.tar.gz.

File metadata

  • Download URL: phantombrowser-0.0.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for phantombrowser-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cb9f64d0de67412886a45ebfa2963714fd61aa2882c41df50e56d8a282d79cc9
MD5 36197cbb73fe15a249dd66ddcccc6f32
BLAKE2b-256 56feddc93cc99adc70d06644084fda89af504ecf89dc69ad8dc1f9afa7f414ee

See more details on using hashes here.

File details

Details for the file phantombrowser-0.0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for phantombrowser-0.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 15a7b9ef500b91513deade9a15b29bcb62b51c41a5bc88b20b22e7c1da020356
MD5 66cf5a51b59f23acf1ed80cb499c13a3
BLAKE2b-256 28e8d238d3ccea2791ce8cf9ee720a61eb9d3eaaaeea2fc53738dc470ef6a9e7

See more details on using hashes here.

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