Skip to main content

Convert bs4 Tags into Json

Project description

PyPi version PyPi pyversions PyPi license

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() and convertAll() which takes two parameters of type bs4.element.Tag, dict and bs4.ResultSet, list respectively.
  • convert() method takes bs4.element.Tag and dict as arguments. bs4.element.Tag is result of soup.find() and dict is an empty dictionary or already constructed dictionary.
  • convertAll() also method takes bs4.ResultSet and list as arguments. bs4.ResultSet is result of soup.findAll() and list 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.0.2.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

bs2json-0.0.0.2-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file bs2json-0.0.0.2.tar.gz.

File metadata

  • Download URL: bs2json-0.0.0.2.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.5rc1

File hashes

Hashes for bs2json-0.0.0.2.tar.gz
Algorithm Hash digest
SHA256 02951486444e6182b513df7ad4e8112ac2ef1a2363f2d1f76832a54b03d51b1f
MD5 80a9e77d77e32e4bcd4bb7ab67a68d10
BLAKE2b-256 c39e06d28e66bb44ff122e88144b0657ee016a6b4b556166076814750057a31f

See more details on using hashes here.

File details

Details for the file bs2json-0.0.0.2-py3-none-any.whl.

File metadata

  • Download URL: bs2json-0.0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.5rc1

File hashes

Hashes for bs2json-0.0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1bd8e4678fb3bc50fbcb4faace592a9cdfff8f1656d64d67cd86373693caa1d1
MD5 def5cb0587d2f96fea4aef43970d6720
BLAKE2b-256 dce37d228e0789bc9c05350c7310351bbe851d2fa71e0ba3e28a05afa848c885

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page