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
11 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 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
19 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 in Python by anonymous
100 views
0 votes
1 answer

How to find count/length of dictionary values of list?

You should have used d.itervalues() instead and ...READ MORE

answered May 13 in Python by John
5 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 in Python by Kirti
10 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
• 56,100 points
32 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.