How to get anchor tags of particular class using BeautifulSoup

0 votes

I am using BeatifulSoup for web scraping and I want to get the anchor tags of a particular class.

I was using this code to get all tags:

soup = BeautifulSoup(html)
for tag in soup.find_all('a'):
    print (tag.text)

But this gets all anchor tags. How to limit it to get links of only a particular class name?

Apr 2, 2019 in Python by Umesh
11,143 views

1 answer to this question.

0 votes

You can specify the class you want to get the anchor tags of. When you do this, only the data of that particular class name will be extracted. Example:

soup = BeautifulSoup(html)
for tag in soup.find_all('a',{"class":"example"}):
    print (tag.text)

answered Apr 2, 2019 by John

Related Questions In Python

0 votes
4 answers

How to print objects of class using print function in Python?

>>> class Test: ... ...READ MORE

answered Dec 16, 2020 in Python by Roshni
• 10,520 points
78,434 views
0 votes
1 answer
0 votes
1 answer

How to get the multiplication table of any number using list comprehension?

Hey @Neha, you can use something like ...READ MORE

answered Jul 8, 2019 in Python by Sakshi
6,648 views
0 votes
1 answer

How to web scrape using python without using a browser?

Yes, you can use the headless mode. ...READ MORE

answered Apr 2, 2019 in Python by Yogi

edited Oct 7, 2021 by Sarfaraz 13,020 views
0 votes
1 answer

How to parse html file to BeautifulSoup?

Hey. Refer to the following code: driver.get("link") html = ...READ MORE

answered Apr 2, 2019 in Python by Kirti
1,896 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP