Skip to content Skip to sidebar Skip to footer

Extracting Href With Beautiful Soup

I use this code to get acces to my link : links = soup.find('span', { 'class' : 'hsmall' }) links.findNextSiblings('a') for link in links: print link['href'] print link.string

Solution 1:

Links is still referring to your soup.find. So you could do something like:

links = soup.find("span", { "class" : "hsmall" }).findNextSiblings('a')
forlinkin links:
    printlink['href']
    print link.string

Solution 2:

Okay, it works now with following code :

linkSpan = soup.find("span", { "class" : "hsmall" })
link = [tag.attrMap['href'] for tag in linkSpan.findAll('a', {'href': True})]
for lien inlink:
  print"LINK = " + lien`

Post a Comment for "Extracting Href With Beautiful Soup"