Home  >  Q&A  >  body text

Convert Html to Json using Python

<p>'I'm trying to find a way to convert HTML to JSON using Python, but I can't find an easy way and have to build my own, which doesn't make sense in large HTML. Can you help me? I've tried using Chat GPT but that didn't help so this is my last resort'</p>
P粉262073176P粉262073176451 days ago640

reply all(1)I'll reply

  • P粉590929392

    P粉5909293922023-08-19 00:31:42

    Don't build your own HTML to JSON converter, use an existing converter, such as html-to-json.

    Use pip install html-to-jsonAfter installation, add the following code to your code:

    import html_to_json
    
    html = "在这里放入你的HTML代码"
    json = html_to_json.convert(html)
    print(json)
    

    The way htmlthe string is generated depends on the source of the HTML: it can be from a file, a URL, etc...

    reply
    0
  • Cancelreply