PDF generation, Web Scraping with headless chrome from browserlify.com
Project description
Browserlify Python SDK
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
- First create a new api key in the Dashboard, and retrieve your API Token.
- We then need to supply these keys to the browserlify
Optionclass 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: The cli tool has a free token: cli_oss_free_token
pdfpdf generationscreenshottake screenshotcontentget website contentscrapeget 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 --paper A3 https://example.org
Take Screenshot
browserlify screenshot -t YOUR_TOKEN -o browserlify.com.png -w 5000 --fullpage https://example.org
Get Page Content
browserlify content -t YOUR_TOKEN -o browserlify.com.json -w 5000 https://example.org
Scrape Page
flows.json is written in browserlify's IDE, and you can get web page content without code
[
{
"action": "waitload",
"timeout": 5000
},
{
"action": "text",
"name": "title",
"selector": "title"
}
]
browserlify scrape -t YOUR_TOKEN -o example.com.json -f flows.json https://example.org
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file browserlify-1.0.4.tar.gz.
File metadata
- Download URL: browserlify-1.0.4.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9f0deb281993117b31eba87a7ed7e2c656f36306d5ff82635f4a70295d23673
|
|
| MD5 |
715504f2f29a061da10be17ade558fbf
|
|
| BLAKE2b-256 |
190415834d7bda2d007a51e8e7464f2ad4c558c6f2ab6d3f8965b7e6f9cbea7b
|
File details
Details for the file browserlify-1.0.4-py3-none-any.whl.
File metadata
- Download URL: browserlify-1.0.4-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b86abbc79f31b43be47ddae9f9d57fd3c800eb3c4ddfcd5baf84374089a0e3d
|
|
| MD5 |
bc153ee5a2ff29012a2eb60156f1094e
|
|
| BLAKE2b-256 |
70d9b3ae43283dce1897da8cd61ae9793d52b3ce8d64d9bd93309e6801c3b860
|