No project description provided
Project description
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'
--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--smooth
may 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 of the seleted node. Arguments--insert_before
and--insert_after
are 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>
--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>
--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>
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
beautifulspoon-0.0.2.tar.gz
(3.8 kB
view details)
Built Distribution
File details
Details for the file beautifulspoon-0.0.2.tar.gz
.
File metadata
- Download URL: beautifulspoon-0.0.2.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.17 CPython/3.7.1 Linux/4.4.0-19041-Microsoft
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0160d674be433e81ddb7edf4b539adb848aca683382a123c0edabc4969d85527 |
|
MD5 | 3a8e8264c6913d8726c2ee31dcc708bc |
|
BLAKE2b-256 | 50901aa72e2ac475dd20f30d00de1d492e460836a2d467bcff077723edcfb44d |
File details
Details for the file beautifulspoon-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: beautifulspoon-0.0.2-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.17 CPython/3.7.1 Linux/4.4.0-19041-Microsoft
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a69553c8317ccdd9fd92571fddbfc92e06da200d48f2abea5f5a2caaee087992 |
|
MD5 | 3926d633435d86d5557432fdf3382604 |
|
BLAKE2b-256 | 7dc563d3d3c19df1e4e2f5f65f3cf4db2343ede90673cd73e7b4ffa3e7ec8d6a |