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
Post a Comment
Write something to CodeWithAbdur!