Let’s discuss the concept of parsing using python. In python we have lot of modules but for parsing we only need urllib and re i.e regular expression. By using both of these libraries we can fetch the data on web pages.
Note that parsing of websites means that fetch the whole source code and that we want to search using a given url link, it will give you the output as the bulk of HTML content that you can’t understand. Let’s see the demonstration with an explanation to let you understand more about parsing.
Code #1: Libraries needed
We have defined a url and some related values that we want to search. Remember that we define values as a dictionary and in this key value pair we define python programming to search on the defined url.
In the first line we encode the values that we have defined earlier, then (line 2) we encode the same data that is understand by machine.
In 3rd line of code we request for values in the defined url, then use the module
urlopen() to open the web document that HTML.
In the last line
read() will help read the document line by line and assign it to respData named variable.
In order to extract the relevant data we apply regular expression. Second argument must be type string and if we want to print the data we apply simple print function.
Below are few examples:
- Python Urllib Module
- PyQt5 - How to automate Progress Bar while downloading using urllib?
- How to Parse and Modify XML in Python?
- Python | Execute and parse Linux commands
- Read, Write and Parse JSON using Python
- Python | How to Parse Command-Line Options
- How to Parse Data From JSON into Python?
- Parse XML using Minidom in Python
- Python | Swap Name and Date using Group Capturing in Regex
- Python program to Count Uppercase, Lowercase, special character and numeric values using Regex
- Python Regex - re.MatchObject.start() and re.MatchObject.end() functions
- Parsing and Processing URL using Python - Regex
- Why is Parse Server the future of Backend As A Service?
- NLP | Using dateutil to parse dates.
- Node | url.parse(urlString, parseQueryString, slashesDenoteHost) API
- How to universally parse JSON into blocks using jQuery ?
- Node.js | path.parse() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.