Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
BeautifulSoup Parsing Error
#7
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
Reply


Messages In This Thread
BeautifulSoup Parsing Error - by slinkplink - Jun-07-2017, 05:12 PM
RE: BeautifulSoup Parsing Error - by nilamo - Jun-07-2017, 05:58 PM
RE: BeautifulSoup Parsing Error - by slinkplink - Jun-07-2017, 09:11 PM
RE: BeautifulSoup Parsing Error - by metulburr - Jun-07-2017, 09:57 PM
RE: BeautifulSoup Parsing Error - by slinkplink - Jun-08-2017, 03:06 PM
RE: BeautifulSoup Parsing Error - by Larz60+ - Jun-08-2017, 08:49 PM
RE: BeautifulSoup Parsing Error - by seco - Feb-12-2018, 02:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Strange ModuleNotFound Error on BeautifulSoup for Python 3.11 Gaberson19 1 990 Jul-13-2023, 10:38 AM
Last Post: Gaurav_Kumar
  [Solved]Help with BeautifulSoup.getText() Error Extra 5 3,750 Jan-19-2023, 02:03 PM
Last Post: prvncpa
  BeautifulSoup not parsing other URLs giddyhead 0 1,194 Feb-23-2022, 05:35 PM
Last Post: giddyhead
  BeautifulSoup: 6k records - but stops after parsing 20 lines apollo 0 1,810 May-10-2021, 05:08 PM
Last Post: apollo
  Logic behind BeautifulSoup data-parsing jimsxxl 7 4,287 Apr-13-2021, 09:06 AM
Last Post: jimsxxl
  Error with NumPy, BeautifulSoup when using pip tsurubaso 7 5,264 Oct-20-2020, 04:34 PM
Last Post: tsurubaso
  Python beautifulsoup pagination error The61 5 3,460 Apr-09-2020, 09:17 PM
Last Post: Larz60+
  BeautifulSoup: Error while extracting a value from an HTML table kawasso 3 3,220 Aug-25-2019, 01:13 AM
Last Post: kawasso
  beautifulsoup error rudolphyaber 7 5,525 May-26-2019, 02:12 PM
Last Post: heiner55
  Beautifulsoup parsing Larz60+ 7 6,062 Apr-05-2017, 03:07 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020