Is it possible to get the line number for the tag being processed? I
have a recursive method that goes through all HTML tags on a page to
make sure they have id and name attributes and that the name and id
match. When I find a tag that does not meet this standard, I'd like
to print out the tag name and the line number where the tag is located
in the HTML file. The column might be good too, but I'd settle for
the line number. I'd like the code to be something like this...
<code>
name_addr = current_tag.get(u'name')
id_addr = current_tag.get(u'id')
if name_addr is None or id_addr is None or name_addr != id_addr:
print "Tag <%s> on line %s of the HTML file does not have valid
attributes." %
(
current_tag.name,
current_tag.line_number)
</code>
The "current_tag.line_number" functionality is what I'm looking for.
I have BeautifulSoup 3 and 4 installed on my system and I can't find
this functionality in either version.