Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
I need to create an HTML Parser that will parse HTML code that I retrieved using either the Requests or Sockets libraries.

I am not allowed to use the Beautiful Soup library, nor anything that creates the parser for me.

How exactly do I parse the HTML and why should I? Could I not just use regex to pick out what I need from the string of HTTP?

What I have tried:

I know about tokenizers and lexers but I don't know how to put it into code.
Posted
Updated 21-Aug-21 14:14pm
v2

1 solution

First question: Why? Avoid reinventing the wheel at any cost. I can understand, as a beginner, you might not enjoy the API of an existing library that does the parsing. But the safer bet is to use an existing library/package for this.

Moving on to your question now.
Quote:
parse HTML code that I retrieved using either the Requests or Sockets libraries.
The response that you receive from the HTTP clients (in Python and other languages) is a string. You can parse the string (which would be an HTML document) following any XML parsing method. But note that, it would be quite difficult to write a parser, especially by keeping all the escape characters in the account.

BeautifulSoup[^] is a nice library that allows you to parse HTML and process it—yes, not just read it, but also filter or query elements and their details.
Quote:
I know about tokenizers and lexers but I don't know how to put it into code.
If you do, then you can use tokenize[^] and process the output; but this is not the recommended approach.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900