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
7,419 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,480 points
57,699 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
2,473 views
0 votes
1 answer
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,058 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer