beautifulspoon
The project is a command line tool build upon beautifulsoup, or say this is a oneliner's tool for dealing with html files. With beautifulspoon, you can easily modify html files in the shell or within the scripts.
Install
pip install beautifulspoon
Usage
Let's prepare a test.html as below:
<html>
<head>
<title>
Hello World
</title>
</head>
<body>
<div class="container" id="root">
<a href="https://www.google.com">
Google
</a>
</div>
</body>
</html>
We can explore the functions of beautifulspoon as follow.
- Get the first HTML element matched selectors in
--select.
bspoon test.html --select '#root a'
- Get all the HTML element matched selectors in
--select.
bspoon test.html --select '#root a' --all
--set_name, change the name of the selected tag.
$ bspoon debug/test.html --select a --set_name button|bspoon --select button
<button href="https://www.google.com">
Google
</button>
--set_attr, set attributes for the seleted tag.
$ bspoon test.html --select a --set_attr class link|bspoon --select a
<a class="link" href="https://www.google.com">
Google
</a>
--append, append a node(HTML) inside the selected node.
$ bspoon test.html --select a --append '<b>Home</b>'|bspoon --select a
<a href="https://www.google.com">
Google
<b>
Home
</b>
</a>
--extend, extend the string(text) of the selected node. Adding--smoothmay help smooth the extended content.
$ bspoon test.html --select a --extend ' It' --smooth|bspoon --select a
<a href="https://www.google.com">
Google
It
</a>
$ bspoon test.html --select a --extend ' It' --smooth|bspoon --select a
<a href="https://www.google.com">
Google It
</a>
--insert, insert a node(HTML) at the POS position inside the selected node. Arguments--insert_beforeand--insert_afterare the same with--insert, with insert position specified at the first and the last slots.
$ bspoon test.html --select div --insert 0 '<br/>'| bspoon --select div
<div class="container" id="root">
<br/>
<a href="https://www.google.com">
Google
</a>
</div>
--insert_before(--ib), insert a node(HTML) before the selected node.
$ bspoon test.html --select a --insert_before '<br/>'|bspoon --select div
<div class="container" id="root">
<br/>
<a href="https://www.google.com">
Google
</a>
</div>
--insert_after(--ia), insert a node(HTML) next to the position of the selected node.
$ bspoon test.html --select a --ia '<br/>'|bspoon --select div
<div class="container" id="root">
<a href="https://www.google.com">
Google
</a>
<br/>
</div>
--clear, clear the inner content of the seleted node.
$ bspoon test.html --select div --clear| bspoon --select div
<div class="container" id="root">
</div>
--decompose, remove the node along with its inner content of the seleted node.
$ bspoon test.html --select div --decompose|bspoon --select body
<body>
</body>
--replace_with, replace the seleted node with HTML.
$ bspoon test.html --select a --replace_with '<br/>'| bspoon --select div
<div class="container" id="root">
<br/>
</div>
--comment, Comment the selected node.
$ bspoon test.html --select a --comment|bspoon --select div
<div class="container" id="root">
<!-- <a href="https://www.google.com">Google</a> -->
</div>
--wrap, wrap the seleted node with tag provided(HTML).
$ bspoon test.html --select a --wrap '<p></p>'
| bspoon --select p
<p>
<a href="https://www.google.com">
Google
</a>
</p>
--unwrap, unwrap the selected node.
$ bspoon test.html --select a --unwrap|bspoon --select div
<div class="container" id="root">
Google
</div>
Metadata
Release files for beautifulspoon 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| beautifulspoon-0.0.4.tar.gz | 3.6 kB | Without provenance | Details for beautifulspoon-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| beautifulspoon-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for beautifulspoon-0.0.4-py3-none-any.whl |
Total release size: 8.0 kB
Release files / beautifulspoon-0.0.4.tar.gz
| Download URL | beautifulspoon-0.0.4.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
36b5f6b1242e4ff8423bc60725415bb927a570e4a2a519804140bd2ec9dcc53a
|
|
BLAKE2b-256 checksum How to use checksums |
dc6903bfc49cdcf6589230bd29042677fff01b1270f5549f79af48dcddb563e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.10.5 Linux/5.15.133.1-microsoft-standard-WSL2
|
Release files / beautifulspoon-0.0.4-py3-none-any.whl
| Download URL | beautifulspoon-0.0.4-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1add578b61f4544293408a1cd61a37ceb2b0074242bbb264e108026cef23b396
|
|
BLAKE2b-256 checksum How to use checksums |
05b0a2a4b0119b0e7a265025732e7516a30c0487006bd96355ddf9ca8536b153
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.10.5 Linux/5.15.133.1-microsoft-standard-WSL2
|
Security for beautifulspoon 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.