[求指导]如何利用脚本/程序从静雅思听网站下载音乐文件?
- eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
- highwind
- 帖子: 1362
- 注册时间: 2008-09-05 23:31
- 系统: LinuxMint17
Re: [求指导]如何从这个网页下载音乐文件?
nae6taiyie0T 写了:@highwindhighwind 写了:哇塞,都不知道怎么感谢了,反正我也只是拿这个学学写脚本而已,如果有人提点再好不过啦。nae6taiyie0T 写了:我刚开试了下, 是可以批量下载的, 我同时下载了6首mp3, 没问题.highwind 写了:我是想一步一步来的,先学下一个 再看能不能下一批,因为每天每个类别都有更新。
因为蛮喜欢这个网站的,就是不知道这样多网站会不会有啥不利的。
Sent from Tapatal
如果考虑网站负担的话, 不妨在晚上睡觉前开始下载, 因为零晨以后的网速快, 网站的访问量也很小了.
我可以帮你写一个下载的程序, 刚才我想了一下, 可以有这些功能:
* 自动分类
* 自动将mp3的标签转为UTF8格式的, 因为它默认的是gbk, 会有乱码.
* 多线程下载.
那个乱码确实没法子,只好自己转了,跟网站提过建议的,不过他们还没回音;
分类的话,其实倒也不打紧,我现在都是按每篇文章来分类(手动建立文件夹而已),当然要是学会怎么自动分也很开心啊;
多线程不错啊,不过每个文件都不大,单线程一会儿也下完了,而且是不是相应可以多下几个文件呢(待求证);
另外如果是注册用户,每次下载好像都会有点小积分,不知道咱要是用脚本下,这个网站能不能识别呢?
已经写好, 需要的话可以联系我, 下载速度还行, 默认是3个下载线程.
我的gtalk 是 gsushzhsosgsu@gmail.com, 也可以发邮件
==========
17:33 更新
把程序上传到了github里, 这里: https://github.com/LiuLang/monkey-video ... er/justing
只需要下载那个justing.py文件, 然后安装必要的python3依赖包, 就可以运行了.
真是万事开头难啊,运行(我用的命令是python3 justing.py)的时候遇到个问题,如下:
代码: 全选
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/lxml/cssselect.py", line 16, in <module>
external_cssselect = __import__('cssselect')
ImportError: No module named 'cssselect'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "justing.py", line 22, in <module>
from lxml.cssselect import CSSSelector as CSS
File "/usr/lib/python3/dist-packages/lxml/cssselect.py", line 18, in <module>
raise ImportError('cssselect seems not to be installed. '
ImportError: cssselect seems not to be installed. See http://packages.python.org/cssselect/
代码: 全选
Requirement already up-to-date: cssselect in /usr/local/lib/python2.7/dist-packages
Cleaning up...

------------------------------------罗哩罗嗦的分割线,以防本人忘记,以供菜鸟参阅------------------------------------------------------
ps:当然我也试过python justing.py运行,不过得在文件首行添加#coding=utf-8,不然中文注释行会报错,但是添加后还是有问题的
代码: 全选
from urllib.error import URLError
ImportError: No module named error
接前文--》后来发现并不是2和3共享了,其实还有个专门的python3-pip,
用pip3 install cssselect安装
代码: 全选
Downloading/unpacking cssselect
Downloading cssselect-0.9.1.tar.gz
Running setup.py egg_info for package cssselect
no previously-included directories found matching 'docs/_build'
Installing collected packages: cssselect
Running setup.py install for cssselect
no previously-included directories found matching 'docs/_build'
Successfully installed cssselect
Cleaning up...
代码: 全选
Requirement already satisfied (use --upgrade to upgrade): cssselect in /usr/local/lib/python3.3/dist-packages
Cleaning up...
然后是miss的mutagenx,一样用pip3安装就行
----------------------------------------------------------------------------------------------------------------------------------------------------
OK ,程序在运行了。。。

最后非常非常地再次感谢nae6taiyie0T。
茕茕
问题大海之一粟:http://forum.ubuntu.org.cn/viewtopic.php?f=74&t=212497
NEMO-Actions使用方法:http://forum.ubuntu.org.cn/viewtopic.php?f=175&t=456548
在线编码转换:http://2cyr.com/decode/?lang=en
问题大海之一粟:http://forum.ubuntu.org.cn/viewtopic.php?f=74&t=212497
NEMO-Actions使用方法:http://forum.ubuntu.org.cn/viewtopic.php?f=175&t=456548
在线编码转换:http://2cyr.com/decode/?lang=en
-
- 帖子: 7
- 注册时间: 2008-03-20 18:27
Re: [求指导]如何利用脚本/程序从静雅思听网站下载音乐文件?
http://www.justing.com.cn/page/ $x .html ===> $title ===> http://dl.justing.com.cn/page/ $title .mp3
只测试了几个,账号也没注册。
发现下载地址都是用title的内容作文件名
只测试了几个,账号也没注册。
发现下载地址都是用title的内容作文件名
-
- 帖子: 482
- 注册时间: 2013-09-13 0:42
- 系统: Debian sid
Re: [求指导]如何从这个网页下载音乐文件?
@highwind
你的学习能力很强嘛.
缺少的那几个python3 库, 我在 https://github.com/LiuLang/monkey-videos 里面都列出来了, 只是你没仔细看而已
只需要用pip3 命令安装上就可以了.
我试着下载了100多首mp3, 没有问题, 速度很快.
写这个程序, 主要精力是花在了学习 mutagenx 模块上, 最后, 将mp3里的ID3tag 进行重写, 下面是一个例子, 里面的信息算是很全了, 都是从网页里面抓取出来的. 在重写之前, 里面的几个字段都是垃圾信息, 还有乱码. 还有更多的功能可以加入, 比如
* 下载完成后弹出桌面通知.
* 自动查找当前最大的ID, 也就是你说的获取每日更新的信息.
* 界面再优化一下.
刚才更新了程序, 已经可以获取当前的最大ID了, 看截图. 我试了下, 这个网站的用户还是挺活跃的, 一会儿的功夫, 就上传了几十个mp3.
你的学习能力很强嘛.
缺少的那几个python3 库, 我在 https://github.com/LiuLang/monkey-videos 里面都列出来了, 只是你没仔细看而已

只需要用pip3 命令安装上就可以了.
我试着下载了100多首mp3, 没有问题, 速度很快.
写这个程序, 主要精力是花在了学习 mutagenx 模块上, 最后, 将mp3里的ID3tag 进行重写, 下面是一个例子, 里面的信息算是很全了, 都是从网页里面抓取出来的. 在重写之前, 里面的几个字段都是垃圾信息, 还有乱码. 还有更多的功能可以加入, 比如
* 下载完成后弹出桌面通知.
* 自动查找当前最大的ID, 也就是你说的获取每日更新的信息.
* 界面再优化一下.
刚才更新了程序, 已经可以获取当前的最大ID了, 看截图. 我试了下, 这个网站的用户还是挺活跃的, 一会儿的功夫, 就上传了几十个mp3.
- highwind
- 帖子: 1362
- 注册时间: 2008-09-05 23:31
- 系统: LinuxMint17
Re: [求指导]如何利用脚本/程序从静雅思听网站下载音乐文件?

首先还是要谢谢啦,又那么快更新了程序。
我当时想要完成这个操作吧,得分这么几个模块:
1.获取今日要下载的文件有那些,其实这个网站更新比较规律,每日(大概凌晨左右)会更新18篇新的文件,散布在各个分类里。我一开始想的是截取网页代码里的有关日期的条目来进行判断(保险起见的话,这还得至少历遍一下各分类里18个url,貌似有些繁琐了),您用ID直接完成的话,就简洁省事的多啦;
2.判断好那些文章要下以后,就可以获取文件链接,然后下载了;
3.分类的话,我因为每天都下,所以就简单地手动归档了,毕竟哪些文章想听,哪些已经更新完(系列文章最后一篇一般会提示[完],或者上下篇的两篇都齐备了)又得花点功夫去实现;
4.最后就是下载下来的文件要转tag,这个在论坛里我也和各位大侠讨论过,有不少实现方式,不过因为现在有了deadbeef,而且平时都是带在身上听,随身听或者ipod之类都不太会乱码,也就不太惧了。当然您这里提到mutagenx,确实很有借鉴价值啊,我也得好好去看看,能直接不显示乱码,何乐而不为呢。
另外python虽说时有耳闻,但编程啥还没基础,代码还且待我慢慢看啊。
ps:构建GUI的部分,是您直接写的,还是用工具搭建好再贴过来的呀?
茕茕
问题大海之一粟:http://forum.ubuntu.org.cn/viewtopic.php?f=74&t=212497
NEMO-Actions使用方法:http://forum.ubuntu.org.cn/viewtopic.php?f=175&t=456548
在线编码转换:http://2cyr.com/decode/?lang=en
问题大海之一粟:http://forum.ubuntu.org.cn/viewtopic.php?f=74&t=212497
NEMO-Actions使用方法:http://forum.ubuntu.org.cn/viewtopic.php?f=175&t=456548
在线编码转换:http://2cyr.com/decode/?lang=en
-
- 帖子: 482
- 注册时间: 2013-09-13 0:42
- 系统: Debian sid
Re: [求指导]如何利用脚本/程序从静雅思听网站下载音乐文件?
GUI 是用gtk3的界面, 代码都在justing.py 里面.
上面有两个截图, 是nautilus 里面点击mp3的右键, 显示出来的属性.
如果只需要下载少数特定的几个, 可以用之前发的那个油㺅脚本, 用起来也算方便.
上面有两个截图, 是nautilus 里面点击mp3的右键, 显示出来的属性.
如果只需要下载少数特定的几个, 可以用之前发的那个油㺅脚本, 用起来也算方便.
- highwind
- 帖子: 1362
- 注册时间: 2008-09-05 23:31
- 系统: LinuxMint17
Re: [求指导]如何利用脚本/程序从静雅思听网站下载音乐文件?
@nae6taiyie0T
不好意思啊,我又回来啦,这几天恶补python,刚开了个头还不是特别懂,不过还是迫不及待地想来问问题。
这次的重点是请教cssselect模块的:
1,首先先请教确认下我的理解是否正确,比如标题(title)吧:
从url解析到tree(一整个网页的源代码倒确实挺像一棵树的结构的)再用CSS(cssselect)解析(用div#title参数得到div下ID为title的元素)后传输给info。(大致应该是这么个流程吧?)
2,然后为了达到下载特定日期上传作品的目的
{
为了好说明我就先自定义下这个网站的结构,姑且以之前提到《瘾的世纪》为例:
下载url:http://dl.justing.com.cn/page/瘾的世纪.mp3
作品url:http://www.justing.com.cn/page/74012.html
分类url:http://www.justing.com.cn/category.jsp?cateId=1
}
我在“分类url”下找到一个timestamp标签,但是这样的话,就牵涉到作品url对应分类url的事,有点麻烦。
后来看到在“作品url”里其实每个作品的上传日期(对应“分类url”的timestamp)都会有一项标记,所以我想要不用它来暂时作为timestamp标签,然后做个判断?可是应该怎么写解析呢,
,试了半天都不行,不太懂网页这方面东西可否稍微提点一下??
多谢啦
ps,我个人是想记录下学习过程,所以想放在论坛上。不知道您喜欢用那种方式联系:论坛,Github,抑或邮箱?
-----------------------------------------------------------------------------信息更新_开始-----------------------------------------------------------------------------
之前也听过爬虫,包括ee的回复里也提到了,现在才知道其实现在弄得东西就是个爬虫呀!
好久没去这个网站的首页http://www.justing.com.cn/index.jsp逛过了
才发现其实似乎有更方便的方法了
首页的源文件里id="tabs-3"下的那十八篇正是我想要的,而且每篇的href="/page/XXX"里正好是所需的ID,如果能解析出来再调用下载模块应该就可以了。
所以现在的问题又回到之前,怎么使用cssselect模块把timestamp,ID这类信息截取出来?
乱七八糟找来些网页解析的东西东拼西凑了一个:
然后请问:
1.我这个是用BeautifulSoup模块搞的,不知道cssselect怎么使(如果用同样的选择参数,就只能截取出第一个来,可是还跟了一个由 转过来的 \xa0 ,这个又该怎么处理呢?)?
2.请问如何把这个整合到您写的脚本里去呢?
-----------------------------------------------------------------------------信息更新_结束-----------------------------------------------------------------------------
不好意思啊,我又回来啦,这几天恶补python,刚开了个头还不是特别懂,不过还是迫不及待地想来问问题。
这次的重点是请教cssselect模块的:
1,首先先请教确认下我的理解是否正确,比如标题(title)吧:
从url解析到tree(一整个网页的源代码倒确实挺像一棵树的结构的)再用CSS(cssselect)解析(用div#title参数得到div下ID为title的元素)后传输给info。(大致应该是这么个流程吧?)
2,然后为了达到下载特定日期上传作品的目的
{
为了好说明我就先自定义下这个网站的结构,姑且以之前提到《瘾的世纪》为例:
下载url:http://dl.justing.com.cn/page/瘾的世纪.mp3
作品url:http://www.justing.com.cn/page/74012.html
分类url:http://www.justing.com.cn/category.jsp?cateId=1
}
我在“分类url”下找到一个timestamp标签,但是这样的话,就牵涉到作品url对应分类url的事,有点麻烦。
后来看到在“作品url”里其实每个作品的上传日期(对应“分类url”的timestamp)都会有一项
代码: 全选
background:url('/stage/img2/bgdetaildeploydate.png') no-repeat
代码: 全选
CSS("style[background='*bgdetaildeploydate*']") ???
多谢啦
ps,我个人是想记录下学习过程,所以想放在论坛上。不知道您喜欢用那种方式联系:论坛,Github,抑或邮箱?
-----------------------------------------------------------------------------信息更新_开始-----------------------------------------------------------------------------
之前也听过爬虫,包括ee的回复里也提到了,现在才知道其实现在弄得东西就是个爬虫呀!


好久没去这个网站的首页http://www.justing.com.cn/index.jsp逛过了
才发现其实似乎有更方便的方法了
首页的源文件里id="tabs-3"下的那十八篇正是我想要的,而且每篇的href="/page/XXX"里正好是所需的ID,如果能解析出来再调用下载模块应该就可以了。
所以现在的问题又回到之前,怎么使用cssselect模块把timestamp,ID这类信息截取出来?

乱七八糟找来些网页解析的东西东拼西凑了一个:
代码: 全选
#!/usr/bin/env python3
from urllib import request
from bs4 import BeautifulSoup as BS
JustingHtml = request.urlopen('http://www.justing.com.cn/index.jsp').read()
JustingSoup = BS(JustingHtml)
JustingSoupFind = JustingSoup.select('#tabs-3 > p > a[target="_blank"]')
for i in range(18):
print(JustingSoupFind[i].text)
1.我这个是用BeautifulSoup模块搞的,不知道cssselect怎么使(如果用同样的选择参数,就只能截取出第一个来,可是还跟了一个由 转过来的 \xa0 ,这个又该怎么处理呢?)?
2.请问如何把这个整合到您写的脚本里去呢?
-----------------------------------------------------------------------------信息更新_结束-----------------------------------------------------------------------------
茕茕
问题大海之一粟:http://forum.ubuntu.org.cn/viewtopic.php?f=74&t=212497
NEMO-Actions使用方法:http://forum.ubuntu.org.cn/viewtopic.php?f=175&t=456548
在线编码转换:http://2cyr.com/decode/?lang=en
问题大海之一粟:http://forum.ubuntu.org.cn/viewtopic.php?f=74&t=212497
NEMO-Actions使用方法:http://forum.ubuntu.org.cn/viewtopic.php?f=175&t=456548
在线编码转换:http://2cyr.com/decode/?lang=en
- highwind
- 帖子: 1362
- 注册时间: 2008-09-05 23:31
- 系统: LinuxMint17
Re: [求指导]如何利用脚本/程序从静雅思听网站下载音乐文件?
另外,麻烦大大帮忙把这个帖子移到python区吧,谢谢拉。 

茕茕
问题大海之一粟:http://forum.ubuntu.org.cn/viewtopic.php?f=74&t=212497
NEMO-Actions使用方法:http://forum.ubuntu.org.cn/viewtopic.php?f=175&t=456548
在线编码转换:http://2cyr.com/decode/?lang=en
问题大海之一粟:http://forum.ubuntu.org.cn/viewtopic.php?f=74&t=212497
NEMO-Actions使用方法:http://forum.ubuntu.org.cn/viewtopic.php?f=175&t=456548
在线编码转换:http://2cyr.com/decode/?lang=en
- highwind
- 帖子: 1362
- 注册时间: 2008-09-05 23:31
- 系统: LinuxMint17
Re: [求指导]如何利用脚本/程序从静雅思听网站下载音乐文件?
代码: 全选
#!/usr/bin/env python3
import urllib.request
from bs4 import BeautifulSoup as BS
NUM = 18
def getHtml(url):
html = urllib.request.urlopen(url).read()
return html
def getMP3(html):
Soup = BS(html)
SoupFind = Soup.select('#tabs-3 > p > a[target="_blank"]')
return SoupFind
def editMP3(mp3):
mp3_E = list(range(NUM))
for i in range(NUM):
mp3_E[i] = mp3[i].text[0:(len(mp3[i].text)-1)]
# 或者用strip好像也行mp3_E[i] = mp3[i].text.strip('\xa0')
return mp3_E
Justingurl = 'http://www.justing.com.cn/index.jsp'
Justinghtml = getHtml(Justingurl)
Justingmp3 = getMP3(Justinghtml)
Justingmp3_E = editMP3(Justingmp3)
def main():
for i in range(NUM):
print('http://dl.justing.com.cn/page/{0}.mp3'.format(Justingmp3_E[i]))
if __name__=="__main__":
main()
另外,如果想用urlretrieve下载会有以下错误:
代码: 全选
UnicodeEncodeError: 'ascii' codec can't encode characters in position
因为不会调用下载,暂时将url保存到文件然后用wget下载,再配合crontab,也算阶段性地解决了本贴一开始提出的问题了,哈哈。

代码: 全选
wget -c --restrict-file-names=nocontrol -i URLLIST_file
茕茕
问题大海之一粟:http://forum.ubuntu.org.cn/viewtopic.php?f=74&t=212497
NEMO-Actions使用方法:http://forum.ubuntu.org.cn/viewtopic.php?f=175&t=456548
在线编码转换:http://2cyr.com/decode/?lang=en
问题大海之一粟:http://forum.ubuntu.org.cn/viewtopic.php?f=74&t=212497
NEMO-Actions使用方法:http://forum.ubuntu.org.cn/viewtopic.php?f=175&t=456548
在线编码转换:http://2cyr.com/decode/?lang=en
- highwind
- 帖子: 1362
- 注册时间: 2008-09-05 23:31
- 系统: LinuxMint17
Re: [求指导]如何利用脚本/程序从静雅思听网站下载音乐文件?
多谢nae6taiyie0T的耐心指导
小结一下:
cssselect选择,在本例中:
当然屁股后面跟着的\xa0还得再加工一下
ASCII码的转换看下面:
------------------------------------2014-03-06 更新------------------------------------
鼓励下自己,今天总算看完,明白了程序,图形化那块有点复杂。
小结一下:
cssselect选择,在本例中:
代码: 全选
from lxml import html
from lxml.cssselect import CSSSelector as CSS
url = 'http://www.justing.com.cn/index.jsp'
tree = html.parse(url)
sel = CSS('div#tabs-3 > p > a[target="_blank"]')
elem=sel(tree)
elem[索引数].text
ASCII码的转换看下面:
代码: 全选
from urllib import parse
parse.quote(文件名)
鼓励下自己,今天总算看完,明白了程序,图形化那块有点复杂。

茕茕
问题大海之一粟:http://forum.ubuntu.org.cn/viewtopic.php?f=74&t=212497
NEMO-Actions使用方法:http://forum.ubuntu.org.cn/viewtopic.php?f=175&t=456548
在线编码转换:http://2cyr.com/decode/?lang=en
问题大海之一粟:http://forum.ubuntu.org.cn/viewtopic.php?f=74&t=212497
NEMO-Actions使用方法:http://forum.ubuntu.org.cn/viewtopic.php?f=175&t=456548
在线编码转换:http://2cyr.com/decode/?lang=en
- highwind
- 帖子: 1362
- 注册时间: 2008-09-05 23:31
- 系统: LinuxMint17
Re: [求指导]如何利用脚本/程序从静雅思听网站下载音乐文件?
学了些队列下载的东西,快了不少。
图形化还是没会,补上这一贴鼓励下自己。
[python]
#!/usr/bin/env python3
import os
#import commands
import urllib.parse
import queue
import threading
from time import time,localtime,strftime
Justing_basedir = "/home/"
Justing_list = "/home/.JustingToday.log"
Justing_downloadNum = 6
class download(threading.Thread):
def __init__(self,que,todir):
threading.Thread.__init__(self)
self.que=que
self.todir=todir
def run(self):
while True:
if not self.que.empty():
#os.system("wget -c -P "+self.todir+" --restrict-file-names=nocontrol "+self.que.get())
#os.system("axel -n6 -a -o "+self.todir+" "+self.que.get())
#commands.getstatus("axel -n6 -a -o "+self.todir+" "+self.que.get())
print(os.system("axel -n6 -a -o "+self.todir+" "+self.que.get()))
else:
break
def startDown(list,todir,num):
listf = open(list,"r",encoding="utf-8")
que=queue.Queue()
for lines in listf:
downloadurl = urllib.parse.quote(lines, safe=':/?=').strip('%0A')
que.put(downloadurl)
for i in range(num):
d=download(que,todir)
d.start()
listf.close()
def makefolder(todir):
timepath = strftime("%Y-%m-%d_%H-%M-%S",localtime(time()))
allpath = os.path.join(todir,timepath)
os.makedirs(allpath)
#print(allpath)
return allpath
if __name__=='__main__':
startDown(Justing_list,makefolder(Justing_basedir),Justing_downloadNum)
# End of the Program
[/python]

图形化还是没会,补上这一贴鼓励下自己。
[python]
#!/usr/bin/env python3
import os
#import commands
import urllib.parse
import queue
import threading
from time import time,localtime,strftime
Justing_basedir = "/home/"
Justing_list = "/home/.JustingToday.log"
Justing_downloadNum = 6
class download(threading.Thread):
def __init__(self,que,todir):
threading.Thread.__init__(self)
self.que=que
self.todir=todir
def run(self):
while True:
if not self.que.empty():
#os.system("wget -c -P "+self.todir+" --restrict-file-names=nocontrol "+self.que.get())
#os.system("axel -n6 -a -o "+self.todir+" "+self.que.get())
#commands.getstatus("axel -n6 -a -o "+self.todir+" "+self.que.get())
print(os.system("axel -n6 -a -o "+self.todir+" "+self.que.get()))
else:
break
def startDown(list,todir,num):
listf = open(list,"r",encoding="utf-8")
que=queue.Queue()
for lines in listf:
downloadurl = urllib.parse.quote(lines, safe=':/?=').strip('%0A')
que.put(downloadurl)
for i in range(num):
d=download(que,todir)
d.start()
listf.close()
def makefolder(todir):
timepath = strftime("%Y-%m-%d_%H-%M-%S",localtime(time()))
allpath = os.path.join(todir,timepath)
os.makedirs(allpath)
#print(allpath)
return allpath
if __name__=='__main__':
startDown(Justing_list,makefolder(Justing_basedir),Justing_downloadNum)
# End of the Program
[/python]
上次由 highwind 在 2014-05-30 9:21,总共编辑 1 次。
茕茕
问题大海之一粟:http://forum.ubuntu.org.cn/viewtopic.php?f=74&t=212497
NEMO-Actions使用方法:http://forum.ubuntu.org.cn/viewtopic.php?f=175&t=456548
在线编码转换:http://2cyr.com/decode/?lang=en
问题大海之一粟:http://forum.ubuntu.org.cn/viewtopic.php?f=74&t=212497
NEMO-Actions使用方法:http://forum.ubuntu.org.cn/viewtopic.php?f=175&t=456548
在线编码转换:http://2cyr.com/decode/?lang=en
- highwind
- 帖子: 1362
- 注册时间: 2008-09-05 23:31
- 系统: LinuxMint17