Saving webpage in a single HTML file, based on playwright
Project description
PageSnap
PageSnap is a tool that allows you to save web pages offline as single-page HTML files, preserving the original appearance of the web page as much as possible. It is developed using Python and Playwright, which means it can also save dynamic JavaScript web pages offline.
The advantage of using single-page HTML format is that users can conveniently open and browse the files with any W3C-compliant browser.
As a Python library, PageSnap can be easily added as a dependency to other projects. If your project uses Python and Playwright, simply import the PageSnap library to add offline-saving capabilities to your pages.
Note: Currently, this project is still in the early stages of feature development and cannot be directly used as a library. The related APIs are still under development. You can keep an eye on the progress, or feel free to clone the project to try it out and share your thoughts.
As a Library
PageSnap provides an asyncio-based API. In your Playwright project, you can complete the offline saving of a page in just two steps. Here's an example code:
# Step1: Hook page to intercept requests and save resources
# note: you can also hook after goto, but you may miss some resources
await hook_page(page)
# Develop your code, doing your actions
await page.goto(url)
# It's better to wait for the page to be fully loaded
await page.wait_for_load_state("networkidle")
# Step2: Get the page content
embedded_html = await page_snap(page)
# Then you can save it to a file
with open(output_filename, 'w', encoding='utf-8') as f:
f.write(embedded_html)
As a Command Line
Use the following pip command to install:
pip install pagesnap
Initialize Playwright:
playwright install
Start using:
pagesnap https://example.com/ test.html
Discussion
If you have any suggestions or improvements, please feel free to submit an issue or pull request. If you like this project, please give it a star.
I am usually active on Sina Weibo and welcome technical discussions there as well.
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
File details
Details for the file pagesnap-0.0.2.tar.gz
.
File metadata
- Download URL: pagesnap-0.0.2.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.0 CPython/3.10.7 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4888cb27a1a3cbf20f23c4e17f2663c83b080e4e8b0264eeccdeb23681ef5f76 |
|
MD5 | 295764f92df5ca2a56c092e80035c50b |
|
BLAKE2b-256 | dff5fd6b613bfc3e1340afcefc1830e048de479d1d022a1504fe53c0ed034dbb |
File details
Details for the file pagesnap-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: pagesnap-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.0 CPython/3.10.7 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0198f6c3d5d274a7f9f36e9dafe6d878289c69d9c9f05d47708035f0bc812c0 |
|
MD5 | cead62f13048dee996ce25fd3c9e0a3c |
|
BLAKE2b-256 | a94a7831aa9358ee54bb1f5f1017d494633422ca29989c9a794d609db870b8f9 |