How to exctract title of links

R

raver2046

here i have a link <a href="http://raver2046.ath.cx/CV/">cv network
admin</a>

how to extract "cv network admin"


here is the code i have find to exctract link but not title of link

----------------------------
import htmllib, formatter, urllib
class x(htmllib.HTMLParser):
def dump(self, tag, attrs):
#print tag,
for a, v in attrs:
if a in ['a', 'src', 'href']:
print v,

print
#def do_img(self, attrs):
# self.dump('img', attrs)
def start_a(self, attrs):
self.dump('a', attrs)
#def start_form(self, attrs):
# self.dump('form', attrs)

y = x(formatter.NullFormatter())
y.feed(urllib.urlopen('http://www.aquabase.org/fish/dump.php3').read())
y.close()
 
P

prasad

import htmllib, formatter, urllib
class x(htmllib.HTMLParser):
inanchor = True # indicates whether we are inside anchor element
def dump(self, tag, attrs):
#print tag,
for a, v in attrs:
if a in ['a', 'src', 'href']:
print v,


print
#def do_img(self, attrs):
# self.dump('img', attrs)
def start_a(self, attrs):
self.dump('a', attrs)
self.inanchor = True # yes now we are in anchor element


def handle_data(self,data):
if self.inanchor:
print data # lets us print the anchor element inner data
self.inanchor = False # we handled the anchor element data
# this is not a nice way, self.inanchor should be set false

# when </a> is reached. try in end_a(self) ...


#def start_form(self, attrs):
# self.dump('form', attrs)

y = x(formatter.NullFormatter())
y.feed(urllib.urlopen('http://www.aquabase.org/fish/dump.php3').read())
y.close()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,213
Messages
2,571,109
Members
47,702
Latest member
gancflex

Latest Threads

Top