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
- How to Parse and Modify XML in Python?
- How to Parse Data From JSON into Python?
- Python | Execute and parse Linux commands
- Read, Write and Parse JSON using Python
- Python | How to Parse Command-Line Options
- Verbose in Python Regex
- Website Blocker Using Python
- Pattern matching in Python with Regex
- Name validation using IGNORECASE in Python Regex
- Python Regex: re.search() VS re.findall()
- Scrape Tables From any website using Python
- Python | Get email alert when the website is up
- Create a Website Alarm Using Python
- Python - Substituting patterns in text using regex
- Find all the patterns of “1(0+)1” in a given string using Python Regex
- The most occurring number in a string using Regex in python
- Python | Program that matches a word containing 'g' followed by one or more e's using regex
- Categorize Password as Strong or Weak using Regex in Python
- Python Regex to extract maximum numeric value from a string
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.