Writing my first web scraping code

Web scrape using python

This is Ramanathan, to all the newbies out here. I work as a software engineer. I wish that I would knew this platform much earlier but nevertheless. Let me start now !!!

My core development language is compiling based and to learn a secondary language I tried my hands on Python.

I always had a keen interest in Python web scraping. In this blog, I will share my journey of writing first code in web scraping.

Here I tried to scrape the headlines of news.google.com with this 13 lines of code. Try out and let me know your feedback.

import requests
from bs4 import BeautifulSoup

URL = "https://news.google.com"
page = requests.get(URL)

soup = BeautifulSoup(page.content, "html.parser")
results = soup.find(id="yDmH0d")
headlines = results.find_all("div",class_="DBQmFf NclIid BL5WZb Oc0wGc xP6mwf j7vNaf")

for headline in headlines:
  printheadline =headline.find("a",class_="DY5T1d RZIKme")
  print(printheadline.text.replace(","," "))