Skip to content

Instantly share code, notes, and snippets.

@youngershen
Created March 25, 2015 02:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youngershen/29cf8562d73f03cd7636 to your computer and use it in GitHub Desktop.
Save youngershen/29cf8562d73f03cd7636 to your computer and use it in GitHub Desktop.
下载songtaste歌曲的脚本
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import urllib2
from bs4 import BeautifulSoup
import requests
BASEURL = 'http://www.songtaste.com/time.php'
def get_song_url(url):
html = urllib2.urlopen(url).read()
soup = BeautifulSoup(html)
data = soup.select('#playicon > div > a')[0]['href']
song_str = data.split(';')[0].split(':')[1].split(',')[2].split('\'')[1]
song_id = url.split('/')[-2]
payload = {'str': song_str, 'sid': song_id, 't': 0}
r = requests.post(BASEURL, data=payload)
song_url = r.text
return song_url
def get_song_data(url):
url = get_song_url(url)
song = urllib2.urlopen(url)
print song
if __name__ == '__main__':
get_song_data('http://www.songtaste.com/song/3467134/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment