Extracting href with Beautiful Soup

后端 未结 2 2015
鱼传尺愫
鱼传尺愫 2021-01-05 15:49

I use this code to get acces to my link :

links = soup.find(\"span\", { \"class\" : \"hsmall\" })
links.findNextSiblings(\'a\')
for link in links:
  print li         


        
相关标签:
2条回答
  • 2021-01-05 16:30

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

    links = soup.find("span", { "class" : "hsmall" }).findNextSiblings('a')
    for link in links:
        print link['href']
        print link.string
    
    0 讨论(0)
  • 2021-01-05 16:48

    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 in link:
      print "LINK = " + lien`
    
    0 讨论(0)
提交回复
热议问题