How to count number of anchor tags got

0 votes

I am using BeautifulSoup to extract some anchor tags from a page.

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

But I don’t know how many anchor tags I have got. I want to have a count of it.

I tried doing this

print (count(tag.text))

But it didn’t work. Any idea how to do it?

Apr 2, 2019 in Python by Kiran
4,383 views

1 answer to this question.

0 votes

I had a similar requirement, this is what I did:

soup = BeautifulSoup(html)
i = 0
for tag in soup.find_all('a',{"class":"qa-user-link"}):
    print (tag.text)
    i=i+1
    print (i)
answered Apr 2, 2019 by Riya
len(soup.find_all('a'))

Related Questions In Python

0 votes
1 answer

how to find factorial of a number?

You can find factorial by many ways. ...READ MORE

answered May 4, 2018 in Python by aayushi
• 750 points
1,707 views
0 votes
2 answers

How to calculate square root of a number in python?

calculate square root in python >>> import math ...READ MORE

answered Apr 2, 2019 in Python by anonymous
5,858 views
+1 vote
1 answer

How to estimate number of clusters through EM in scikit-learn

For future reference, the fixed function looks ...READ MORE

answered Sep 26, 2018 in Python by Priyaj
• 58,020 points
1,258 views
–1 vote
2 answers
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,066 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,936 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to count the number of elements in a list?

To count the number of elements of ...READ MORE

answered May 27, 2019 in Python by Nisa
• 1,090 points
5,240 views
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