Feb-12-2018, 02:55 PM
To scrape specific elements using the class attribute as an example:
from urllib.request import urlopen from urllib.error import HTTPError from urllib.error import URLError from bs4 import BeautifulSoup try: html = urlopen("https://likegeeks.com/") except HTTPError as e: print(e) except URLError: print("Server down or incorrect domain") else: res = BeautifulSoup(html.read(),"html5lib") tags = res.findAll("h3", {"class": "post-title"}) for tag in tags: print(tag.getText())Also, you can use findAll like this:
tags = res.findAll("span", "a" "img")Or by inner text:
tags = res.findAll(text="Python Programming Basics with Examples")Check this tutorial: Python web scraping