{"id":18774103,"url":"https://github.com/thomasborgen/soup2dict","last_synced_at":"2025-04-13T09:21:12.166Z","repository":{"id":45271043,"uuid":"311472028","full_name":"thomasborgen/soup2dict","owner":"thomasborgen","description":"Transforms BeautifulSoup soup to python dict or json","archived":false,"fork":false,"pushed_at":"2021-12-26T07:50:11.000Z","size":66,"stargazers_count":6,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T00:54:56.007Z","etag":null,"topics":["beautifulsoup","beautifulsoup4","dict","json","parser","transformer"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thomasborgen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-09T21:40:54.000Z","updated_at":"2024-06-10T17:47:59.000Z","dependencies_parsed_at":"2022-09-19T09:30:39.078Z","dependency_job_id":null,"html_url":"https://github.com/thomasborgen/soup2dict","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasborgen%2Fsoup2dict","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasborgen%2Fsoup2dict/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasborgen%2Fsoup2dict/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasborgen%2Fsoup2dict/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thomasborgen","download_url":"https://codeload.github.com/thomasborgen/soup2dict/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248689365,"owners_count":21145921,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["beautifulsoup","beautifulsoup4","dict","json","parser","transformer"],"created_at":"2024-11-07T19:37:21.825Z","updated_at":"2025-04-13T09:21:12.142Z","avatar_url":"https://github.com/thomasborgen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# soup2dict\n\nBeautifulSoup4 to python dictionary converter\n___\n![test](https://github.com/thomasborgen/soup2dict/workflows/test/badge.svg)\n[![codecov](https://codecov.io/gh/thomasborgen/soup2dict/branch/master/graph/badge.svg)](https://codecov.io/gh/thomasborgen/soup2dict)\n[![Python Version](https://img.shields.io/pypi/pyversions/soup2dict.svg)](https://pypi.org/project/soup2dict/)\n[![wemake-python-styleguide](https://img.shields.io/badge/style-wemake-000000.svg)](https://github.com/wemake-services/wemake-python-styleguide)\n___\n\n\n## Why\n\nIts nice to have a convenient way to change your soup into dict.\n\n## Installation\n\nGet package with pip or poetry\n\n```sh\npip install soup2dict\n```\n\n```sh\npoetry add soup2dict\n```\n\n## Example\n\n```python\nimport simplejson\nfrom bs4 import BeautifulSoup\n\nfrom soup2dict import convert\n\nhtml_doc = \"\"\"\n\u003chtml\u003e\nhei\n\u003chead\u003e\n    \u003ctitle\u003eThe Dormouse's story\u003c/title\u003e\n    \u003ctitle\u003ebob\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003cp class=\"title\"\u003eThe \u003cb\u003eDormouse's story\u003c/b\u003e\u003c/p\u003e\n    \u003cp class=\"story\"\u003eOnce upon a time there were three little sisters;\n    and their names were\n    \u003ca href=\"http://example.com/elsie\" class=\"sister\" id=\"link1\"\u003eElsie\u003c/a\u003e,\n    \u003ca href=\"http://example.com/lacie\" class=\"sister\" id=\"link2\"\u003eLacie\u003c/a\u003e and\n    \u003ca href=\"http://example.com/tillie\" class=\"sister\" id=\"link3\"\u003eTillie\u003c/a\u003e;\n    and they lived at the bottom of a well.\u003c/p\u003e\n\n    \u003cp class=\"story\"\u003e...\u003c/p\u003e\n\"\"\"\n\n\n# Create soup from html_doc data\nsoup = BeautifulSoup(html_doc, 'html.parser')\n\n# Convert it to a dictionary with convert()\ndict_result = convert(soup)\n\nwith open('output.json', 'w') as output_file:\n    output_file.write(\n        simplejson.dumps(dict_result, indent=2),\n    )\n\n```\n\n## Output\n\n```json\n{\n  \"html\": [\n    {\n      \"#text\": \"hei The Dormouse's story bob The Dormouse's story Once upon a time there were three little sisters; and their names were Elsie , Lacie and Tillie ; and they lived at the bottom of a well. ...\",\n      \"navigablestring\": [\n        \"hei\"\n      ],\n      \"head\": [\n        {\n          \"#text\": \"The Dormouse's story bob\",\n          \"title\": [\n            {\n              \"#text\": \"The Dormouse's story\",\n              \"navigablestring\": [\n                \"The Dormouse's story\"\n              ]\n            },\n            {\n              \"#text\": \"bob\",\n              \"navigablestring\": [\n                \"bob\"\n              ]\n            }\n          ]\n        }\n      ],\n      \"body\": [\n        {\n          \"#text\": \"The Dormouse's story Once upon a time there were three little sisters; and their names were Elsie , Lacie and Tillie ; and they lived at the bottom of a well. ...\",\n          \"p\": [\n            {\n              \"@class\": [\n                \"title\"\n              ],\n              \"#text\": \"The Dormouse's story\",\n              \"navigablestring\": [\n                \"The\"\n              ],\n              \"b\": [\n                {\n                  \"#text\": \"Dormouse's story\",\n                  \"navigablestring\": [\n                    \"Dormouse's story\"\n                  ]\n                }\n              ]\n            },\n            {\n              \"@class\": [\n                \"story\"\n              ],\n              \"#text\": \"Once upon a time there were three little sisters; and their names were Elsie , Lacie and Tillie ; and they lived at the bottom of a well.\",\n              \"navigablestring\": [\n                \"Once upon a time there were three little sisters;\\n    and their names were\",\n                \",\",\n                \"and\",\n                \";\\n    and they lived at the bottom of a well.\"\n              ],\n              \"a\": [\n                {\n                  \"@href\": \"http://example.com/elsie\",\n                  \"@class\": [\n                    \"sister\"\n                  ],\n                  \"@id\": \"link1\",\n                  \"#text\": \"Elsie\",\n                  \"navigablestring\": [\n                    \"Elsie\"\n                  ]\n                },\n                {\n                  \"@href\": \"http://example.com/lacie\",\n                  \"@class\": [\n                    \"sister\"\n                  ],\n                  \"@id\": \"link2\",\n                  \"#text\": \"Lacie\",\n                  \"navigablestring\": [\n                    \"Lacie\"\n                  ]\n                },\n                {\n                  \"@href\": \"http://example.com/tillie\",\n                  \"@class\": [\n                    \"sister\"\n                  ],\n                  \"@id\": \"link3\",\n                  \"#text\": \"Tillie\",\n                  \"navigablestring\": [\n                    \"Tillie\"\n                  ]\n                }\n              ]\n            },\n            {\n              \"@class\": [\n                \"story\"\n              ],\n              \"#text\": \"...\",\n              \"navigablestring\": [\n                \"...\"\n              ]\n            }\n          ]\n        }\n      ]\n    }\n  ]\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomasborgen%2Fsoup2dict","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthomasborgen%2Fsoup2dict","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomasborgen%2Fsoup2dict/lists"}