14 12
发新话题
打印

[shell脚本] Shell编程 怎么实现自动下载百度排行mp3程序

Shell编程 怎么实现自动下载百度排行mp3程序

看了很长时间shell 编程,现在想试一下:
怎么实现自动下载百度排行mp3程序
譬如:怎么下载 百度的新歌TOP100中的前五首。详细的见附件

但是不知道从何下手,请各位大虾指点!

[ 本帖最后由 DUT_girl 于 2008-4-17 15:57 编辑 ]

附件

untitled.jpg (893.18 KB)

2008-4-17 15:57

untitled.jpg

百芳园中欲独艳
万艳丛中却自芳

TOP

1. download or analysis the web page, locate "新歌TOP100" and find the URLs of songs;
2. wget those URLs
3. done~
春有百花秋有月,夏有凉风冬有雪,若无闲事挂心头,便是人间好时节!

TOP

现在碰到这样一个问题:怎么得到网页上某个板块对应的url。
譬如我怎么得到“新歌TOP100”的URL呢?即怎么根据名字“新歌TOP100”获得它的URL

[ 本帖最后由 DUT_girl 于 2008-4-18 10:18 编辑 ]
百芳园中欲独艳
万艳丛中却自芳

TOP

1. “新歌TOP100” can be drilled into, and it define a href like this:
<td nowrap="nowrap">• <a id="top1" href="newhits.html?top1" class="p14" target="_top">新歌TOP100</a></td>
2. newhits.html?top1 redirects to http://list.mp3.baidu.com/list/newhits.html
3. in this page, you may find links of songs.

I highly suggest you could think it over before rise questions.
春有百花秋有月,夏有凉风冬有雪,若无闲事挂心头,便是人间好时节!

TOP

匆忙间写就一个,方法比较笨,希望能抛砖引玉

#!/bin/bash

#download songs from Baidu MP3 automatically

#新歌TOP100
INDEX_WEB="http://list.mp3.baidu.com/list/newhits.html"
#歌曲top500
#INDEX_WEB="http://list.mp3.baidu.com/topso/mp3topsong.html"
#经典老歌
#INDEX_WEB="http://list.mp3.baidu.com/list/oldsong.html"
#电影金曲
#INDEX_WEB="http://list.mp3.baidu.com/list/movies.html"
#民歌精选
#INDEX_WEB="http://list.mp3.baidu.com/minge/mp3topsong.html"
#校园歌曲
#INDEX_WEB="http://list.mp3.baidu.com/xiaoyuan/mp3topsong.html"
#轻音乐
#INDEX_WEB="http://list.mp3.baidu.com/list/qingyinyue.html"
#少儿歌曲
#INDEX_WEB="http://list.mp3.baidu.com/list/shaoergequ.html"
#摇滚歌曲榜
#INDEX_WEB="http://list.mp3.baidu.com/list/yaogun.html"
#流金岁月
#INDEX_WEB="http://list.mp3.baidu.com/list/liujinsuiyue.html"

# original web addr in mp3.baidu.com
#INDEX_WEB="http://list.mp3.baidu.com/topso/mp3topsong.html?top2"
#rename of top100 web
LOCAL_INDEX=top100
#file with songs name and first link of the songs
SONGS_ADDRS_NAMES=top100_sangs
#songs name
SONGS_NAMES=top100_names

#links for a special song
LINKS_OF_SONG=links_of_song
LINKS_OF_SONG_ADDR_ONLY=links_of_song_addr

#a link in LINKS_OF_SONG, anylize mp3 download addr
LINK_TMP=link_tmp



#sed '/^$/d' ----delete blank line
#sed 's/<b>//g' ----delete <b>

function GetNameAndFirstAddr()
{
    echo "Anylse addrs and songs' names"

    #get songs name and first links; resolve <b></b> issue
    cat $LOCAL_INDEX |grep target=_blank |grep '<td' |sed 's/<b>//g' |sed 's/<\/b>//g' >$SONGS_ADDRS_NAMES
   
    #get songs name
    cat $SONGS_ADDRS_NAMES |awk -F\< '{print $3}' |awk -F\> '{print $2}' |sed '/^$/d' >$SONGS_NAMES

    echo "first addrs and names over"
}

# $1 = $SONGS_NAMES
# $2 = $SONGS_ADDRS_NAMES
function GoForSongs()
{
    echo "Download songs one by one"
   
    name="xxx"

    {
        while [ "$name" != "" ]
        do
            read name

            first_addr=`grep "$name" $2 |awk -F\> '{print $2}' |awk -F\" '{print $2}'`

            DownloadStart $name $first_addr
            #break

            #echo $name >>aaa
            #echo $first_addr >>aaa
        done
    }< $1

}

# $1 song name
# $2 song first addr
function DownloadStart()
{
    echo
    echo "start to download  $1"

    wget "$2" -O$LINKS_OF_SONG
   
    #cat $LINKS_OF_SONG |grep '\&word' |grep 'mp3' |grep -v 'Tit' |awk -F\" '{print $2}' >$LINKS_OF_SONG_ADDR_ONLY
    #cat $LINKS_OF_SONG |grep '\&word' |grep 'mp3' |awk -F\" '{print $2}' |grep -v 'Tit' >$LINKS_OF_SONG_ADDR_ONLY
    cat $LINKS_OF_SONG |grep '\&word=mp3' |awk -F\" '{print $2}'  >$LINKS_OF_SONG_ADDR_ONLY

    link="xxxx"
    {
        while [ "$link" != "" ]
        do
            read link
            wget "$link" -O$LINK_TMP

            #download song
            
            #song's addr
            song_addr=`cat $LINK_TMP |grep '\<br\>' |awk -F\" '{print $2}'`

            #if [ -z "$song_addr" ]
            #then
            #    echo "error song_addr"
            #    continue
            #fi

            echo
            echo "download from $song_addr"
            echo

            #----------------------------to be improved------------------------------------#song's type .mp3
            song_extention=`echo $song_addr |awk -F\. '{print $NF}'`
            #echo "$song_extention"
            #song_extention="mp3"
            echo "$1.$song_extention"
            wget "$song_addr" -O"$1.$song_extention"
            #axel -a -o"$2.$song_extention" "$song_addr"

            #if wget return error, try next link
            if [ $? -eq 1 ]
            then
                echo "link error, try next"
                continue
            else
                echo "Download $1 over"
                break
            fi
        done
    }< $LINKS_OF_SONG_ADDR_ONLY

}

#==============================Start to work====================
#download top100 web and rename
wget "$INDEX_WEB" -O$LOCAL_INDEX

GetNameAndFirstAddr
GoForSongs $SONGS_NAMES $SONGS_ADDRS_NAMES
#===============================================================

#remove all template files
#rm -f $LOCAL_INDEX $SONGS_ADDRS_NAMES $SONGS_NAMES $LINKS_OF_SONG $LINKS_OF_SONG_ADDR_ONLY $LINK_TMP

exit 0

TOP

http://bbs.chinaunix.net/thread-789960-1-1.html

2006年写的,现在估计用不了了
----

TOP

我现在在处理网页的时候遇到一个问题:   ,在html语言中试表示空格的, 怎么删除他。
驶过好几个了,都不好使
sed 's/\&bsp\;//g'
sed 's/&bsp;//g'

应该怎么做啊??
百芳园中欲独艳
万艳丛中却自芳

TOP

引用:
原帖由 DUT_girl 于 2008-5-28 16:23 发表
我现在在处理网页的时候遇到一个问题:    ,在html语言中试表示空格的, 怎么删除他。
驶过好几个了,都不好使
sed 's/\&bsp\;//g'
sed 's/&bsp;//g'

应该怎么做啊??
应该是nbsp吧?
用sed这样
复制内容到剪贴板
代码:
sed -e 's/\&nbsp\;//g'
--------------------------------------------------
埋头调着程序,不知不觉,黄瓜已经爬上了架子

TOP

如何下载shell编程?(关于CAD)
没有

TOP

无语. . . ..
看的不太懂. . . . . .

怎么样可以更快的学习shell?

TOP

 14 12
发新话题