Scraping Post Titles from a Blog Page in Python


import requests #pip install requests
from bs4 import BeautifulSoup #pip install beautifulsoup4

url = "https://www.pharmacymcqs.com/"
resposne = requests.get(url)
# print(resposne)

soup = BeautifulSoup(resposne.content, "lxml")
# print(soup)

post_titles = soup.find_all("h2", {"class":"post-title"})

# to print only the first title
# print(post_titles[0].getText())

# to print all the titles from the blog page
for title in post_titles:
      print(title.getText())
   

    

Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

The Basic Structure of a Full-Stack Web App

Unlocking Web Design: A Guide to Mastering CSS Layout Modes