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 in Python by Kiran

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)
    print (i)
answered Apr 2 by Riya

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
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 in Python by anonymous
+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
• 56,520 points
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 in Python by Kirti
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 in Python by Nisa
• 1,090 points