Reading selected webpage content using Python Web Scraping Last Updated : 17 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Prerequisite: Downloading files in Python, Web Scraping with BeautifulSoup We all know that Python is a very easy programming language but what makes it cool are the great number of open source library written for it. Requests is one of the most widely used library. It allows us to open any HTTP/HTTPS website and let us do any kind of stuff we normally do on web and can also save sessions i.e cookie. As we all know that a webpage is just a piece of HTML code which is sent by the Web Server to our Browser, which in turn converts into the beautiful page. Now we need a mechanism to get hold of the HTML source code i.e finding some particular tags with a package called BeautifulSoup. Installation: pip3 install requests pip3 install beautifulsoup4 We take an example by reading a news site Hindustan Times The code can be divided into three parts. Requesting a webpage Inspecting the tags Print the appropriate contents Steps: Requesting a webpage: First we see right click on the news text to see the source code Inspecting the tags: We need to figure in which body of the source code contains the news section we want to scrap. It is the under ul,i.e unordered list, "searchNews" which contains the news section. Note The news text is present in the anchor tag text part. A close observation gives us the idea that all the news are in li, list, tags of the unordered tag. Print the appropriate contents: The content is printed with the help of code given below. Python import requests from bs4 import BeautifulSoup def news(): # the target we want to open url='http://www.hindustantimes.com/top-news' #open with GET method resp=requests.get(url) #http_respone 200 means OK status if resp.status_code==200: print("Successfully opened the web page") print("The news are as follow :-\n") # we need a parser,Python built-in HTML parser is enough . soup=BeautifulSoup(resp.text,'html.parser') # l is the list which contains all the text i.e news l=soup.find("ul",{"class":"searchNews"}) #now we want to print only the text part of the anchor. #find all the elements of a, i.e anchor for i in l.findAll("a"): print(i.text) else: print("Error") news() Output Successfully opened the web page The news are as follow :- Govt extends toll tax suspension, use of old notes for utility bills extended till Nov 14 Modi, Abe seal historic civil nuclear pact: What it means for India Rahul queues up at bank, says it is to show solidarity with common man IS kills over 60 in Mosul, victims dressed in orange and marked 'traitors' Rock On 2 review: Farhan Akhtar, Arjun Rampal's band hasn't lost its magic Rumours of shortage in salt supply spark panic among consumers in UP Worrying truth: India ranks first in pneumonia, diarrhoea deaths among kids To hell with romance, here's why being single is the coolest way to be India vs England: Cheteshwar Pujara, Murali Vijay make merry with tons in Rajkot Akshay-Bhumi, SRK-Alia, Ajay-Parineeti: Age difference doesn't matter anymore Currency ban: Only one-third have bank access; NE, backward regions worst hit Nepal's central bank halts transactions with Rs 500, Rs 1000 Indian notes Political upheaval in Punjab after SC tells it to share Sutlej water Let's not kid ourselves, with Trump, what we have seen is what we will get Want to colour your hair? Try rose gold, the hottest hair trend this winter References Requests BeautifulSoup Http_status_codes Create Quiz Comment S Shubham Choudhary 1 0 Improve S Shubham Choudhary 1 0 Improve Article Tags : Web Scraping Explore Introduction to Web ScrapingIntroduction to Web Scraping 5 min read What is Web Scraping and How to Use It? 5 min read Web Scraping - Legal or Illegal? 4 min read Difference between Web Scraping and Web Crawling 2 min read Web Scraping using cURL in PHP 2 min read Basics of Web ScrapingHTML Basics 7 min read Tags vs Elements vs Attributes in HTML 2 min read CSS Introduction 3 min read CSS Syntax 3 min read JavaScript Cheat Sheet - A Basic Guide to JavaScript 15+ min read Setting Up the EnvironmentInstalling BeautifulSoup: A Beginner's Guide 2 min read How to Install Requests in Python - For Windows, Linux, Mac 7 min read Selenium Python Introduction and Installation 2 min read How to Install Python Scrapy on Windows? 2 min read Extracting Data from Web PagesImplementing Web Scraping in Python with BeautifulSoup 6 min read How to extract paragraph from a website and save it as a text file? 2 min read Extract all the URLs from the webpage Using Python 2 min read How to Scrape Nested Tags using BeautifulSoup? 3 min read Extract all the URLs that are nested within <li> tags using BeautifulSoup 4 min read Clean Web Scraping Data Using clean-text in Python 2 min read Fetching Web PagesGET and POST Requests Using Python 7 min read BeautifulSoup - Scraping Paragraphs from HTML 3 min read HTTP Request MethodsGET method - Python requests 2 min read POST method - Python requests 2 min read PUT method - Python requests 2 min read DELETE method- Python requests 2 min read HEAD method - Python requests 2 min read PATCH method - Python requests 3 min read Searching and Extract for specific tags BeautifulsoupPython BeautifulSoup - find all class 2 min read BeautifulSoup - Search by text inside a tag 4 min read Scrape Google Search Results using Python BeautifulSoup 3 min read Get tag name using Beautifulsoup in Python 1 min read Extracting an attribute value with beautifulsoup in Python 2 min read BeautifulSoup - Modifying the tree 5 min read Find the text of the given tag using BeautifulSoup 2 min read Remove spaces from a string in Python 2 min read Understanding Character Encoding 6 min read XML parsing in Python 7 min read Python - XML to JSON 4 min read Scrapy BasicsScrapy - Command Line Tools 5 min read Scrapy - Item Loaders 15+ min read Scrapy - Item Pipeline 10 min read Scrapy - Selectors 7 min read Scrapy - Shell 9 min read Scrapy - Spiders 11 min read Scrapy - Feed exports 5 min read Scrapy - Link Extractors 5 min read Scrapy - Settings 7 min read Scrapy - Sending an E-mail 2 min read Scrapy - Exceptions 7 min read Selenium Python BasicsNavigating links using get method in Selenium - Python 2 min read Interacting with Webpage - Selenium Python 4 min read Locating single elements in Selenium Python 5 min read Locating multiple elements in Selenium Python 5 min read Locator Strategies - Selenium Python 2 min read Writing Tests using Selenium Python 2 min read Like