Skip to main content

PDF generation, Web Scraping with headless chrome from browserlify.com

Project description

Browserlify Python SDK

GitHub

The Browserlify API Python Library

Usage

Requirements

You should be signed up as a developer on the browserlify.com so that you can create and manage your API token, It's free Sign up.

Installation

To easily install or upgrade to the latest release, use pip.

pip install --upgrade browserlify

Table of Contents

Getting Started

  1. First create a new api key in the Dashboard, and retrieve your API Token.
  2. We then need to supply these keys to the browserlify Option class so that it knows how to authenticate.
from browserlify import pdf, Option

opt = Option(YOUR_TOKEN)

PDF generation

from browserlify import pdf, Option

opt = Option(YOUR_TOKEN)
opt.paper = 'A4'
opt.full_page = True
opt.wait_load = 5000 # Wait document loaded <= 5,000 ms

try:
    content = pdf('https://example.org', opt)
    open('example.org.pdf','wb+').write(content)
except Exception as bre:
    print('pdf fail', bre)

Screenshot

from browserlify import screenshot, Option

opt = Option(YOUR_TOKEN)
opt.full_page = True
opt.wait_load = 5000 # Wait document loaded <= 5,000 ms

try:
    content = screenshot('https://example.org', opt)
    open('example.org.png','wb+').write(content)
except Exception as bre:
    print('screenshot fail', bre)

Web Scraping

from browserlify import scrape, Option,Flow

opt = Option(YOUR_TOKEN)
opt.flows = [
    Flow(action="waitload", timeout=5000), # Wait document loaded <= 5,000 ms
    Flow(name="title", action="text", selector="h1")
]

try:
    content = scrape('https://example.org', opt)
    print(content)
    # output:
    # {"page":1,"data":{"title":"Example Domain"}}
except Exception as bre:
    print('scrape fail', bre)

cli

scripts/browserlify:

  • pdf pdf generation
  • screenshot take screenshot
  • content get website content
  • scrape get website content
browserlify cli tool

positional arguments:
  {pdf,screenshot,content,scrape}
                        commands help
    pdf                 pdf generation help
    screenshot          take screenshot help
    content             get content help
    scrape              web scrape help

optional arguments:
  -h, --help            show this help message and exit
  --version, -v         show program's version number and exit

convert url to pdf

browserlify pdf -t YOUR_TOKEN -o browserlify.com.pdf -w 5000 --fullpage https://browserlify.com

take screenshot

browserlify screenshot -t YOUR_TOKEN -o browserlify.com.png -w 5000  --fullpage  https://browserlify.com

get page content

browserlify content -t YOUR_TOKEN -o browserlify.com.json -w 5000 https://browserlify.com

scrape page

browserlify scrape -t YOUR_TOKEN -o example.com.json -w 5000 -f flows.json https://example.com

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

browserlify-1.0.2.tar.gz (9.4 kB view details)

Uploaded Source

File details

Details for the file browserlify-1.0.2.tar.gz.

File metadata

  • Download URL: browserlify-1.0.2.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for browserlify-1.0.2.tar.gz
Algorithm Hash digest
SHA256 f407902d21c9b66d6ea2ba0e8d1dcb16e27e7ae3e992999cfa267c9dc2239286
MD5 2d758c8e13dd97f1a788eda09e363e69
BLAKE2b-256 dc41242e7506f54bce1144f13343a1a9b8f34ee1bf365dbe696f62d2271df904

See more details on using hashes here.

Supported by

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