Convert bs4 Tags into Json
Project description
Convert HTML Tags of BeautifulSoup class to JSON data using.
Installation
This package is available on PyPi. Just use pip install -U bs2json
to install it. Then you can import it using from bs2json import bs2json
.
Example Syntax
from bs4 import BeautifulSoup
from requests import get
from bs2json import bs2json
html = get('https://ijazurrahim.com').text
soup = BeautifulSoup(html,'lxml')
converter = bs2json()
tag = soup.find('ul')
json = converter.convert(tag)
print(json)
Output
Upon running the Above Program, you will get the following output
{'ul': {'attributes': {'class': ['nav', 'nav-justified', 'justify-content-center']}, 'li': [{'attributes': {'class': ['nav-item'], 'onclick': "window.location='#home';change();"}, 'a': {'attributes': {'href': '#home'}, 'text': 'Home'}, 'text': ''}, {'attributes': {'class': ['nav-item'], 'onclick': "window.location='#skills';change();"}, 'a': {'attributes': {'href': '#skills'}, 'text': 'Skills'}, 'text': ''}, {'attributes': {'class': ['nav-item'], 'onclick': "window.location='#contact';change();"}, 'a': {'attributes': {'href': '#contact'}, 'text': 'Contact'}, 'text': ''}, {'attributes': {'class': ['nav-item'], 'onclick': "window.location='#blog';change();"}, 'a': {'attributes': {'href': '#blog'}, 'text': 'Blog'}, 'text': ''}], 'text': ''}}
Other Methods
- There are total 2 methods
convert()
andconvertAll()
which takes two parameters of typebs4.element.Tag
,dict
andbs4.ResultSet
,list
respectively. convert()
method takesbs4.element.Tag
anddict
as arguments.bs4.element.Tag
is result ofsoup.find()
anddict
is an empty dictionary or already constructed dictionary.convertAll()
also method takesbs4.ResultSet
andlist
as arguments.bs4.ResultSet
is result ofsoup.findAll()
andlist
is an empty list or already constructed list.
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
bs2json-0.0.1.tar.gz
(2.6 kB
view details)
File details
Details for the file bs2json-0.0.1.tar.gz
.
File metadata
- Download URL: bs2json-0.0.1.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4dd703a11e76a9f0047de4ddddc2169bda684a080c4f20d1b95699ad0325502e |
|
MD5 | 2a5dbc52cb7acd8e61380807c3290f3d |
|
BLAKE2b-256 | 1168c1105e55c7c09e1935f060827baa80c99f7a3bf15531877552155f0a290f |