2014-09-12 67 views
-1

我想在站點中找到所有音頻文件,如.mp3,.wav,.ogg,.wma等使用Python。 這是我的代碼>>使用python查找頁面中的所有音頻鏈接

url = urllib.request.urlopen(link) 
    content = url.read() 
    soup = BeautifulSoup(content) 
    links = [a['href'] for a in soup.find_all('a',href=re.compile('http.*\.mp3'))] 
    print (str(len(links)) + " Audios Found ") 
    # print (links) 
    print("\n".join(links)) 

這隻能找到MP3播放鏈接。 我還想要其他音頻鏈接。

回答

1

由於您使用正則表達式來選擇鏈接,更改此行

links = [a['href'] for a in soup.find_all('a',href=re.compile('http.*\.mp3'))] 

links = [a['href'] for a in soup.find_all('a',href=re.compile('http.*\.(mp3|wav|ogg|wma)'))] 
+0

感謝的人@kums。其他方式將也很有幫助.. :) – 2014-09-13 07:39:37

相關問題