如何获得第一个获得。(“href”)

时间:2015-02-23 06:27:18

标签: python beautifulsoup dataframe

try: 
    link = music.find_all("a")
    #print link
    for link_music in link:
            music= link_music.get('href')
            print music
            musicData['Link'].append(music)
except:
    musicData['Link'].append("")

dr = pd.DataFrame(musicData)
dr

我试图只获得' href'用' http'在它..但.get(href)也得到了#'#'

Output of Code#1


try: 
    link = music.find_all("a")
    #print link
    for link_music in link:
            music= link_music.get('href')[2:]
            #print music
            musicData['Link'].append(music)
except:
    musicData['Link'].append("")

dr = pd.FataFrame(musicData)
dr

以[2:],我得到了' href'但是对于一些令人反感的事情而言。从https://被删除,表格如图2所示填充。

Output of Code#2


如何使数据框架只有' http href'

0 个答案:

没有答案