-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQnwzMultiDownLoad.py
86 lines (78 loc) · 2.71 KB
/
QnwzMultiDownLoad.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# -*- coding: utf-8 -*-
import urllib2
import re
import os
def Download(url,output):
print url
print "downloading..."
try:
response = urllib2.urlopen(url)
resourceFile = open(output,"wb")
resourceFile.write(response.read())
resourceFile.close()
except Exception,e:
output = open('./thefile.txt', "a")
output.write("\n" + url)
output.close()
def DownloadMP3(url,ext = "mp3",output = "./"):
#1.domain
index = url.rfind("/");
domain = url[0:index+1];
request = urllib2.Request(url)
response = urllib2.urlopen(request)
#2.content
content = response.read()
#print content
#3.resource
mode = '\"([^\"]+'+ext+')\"'
pattern = re.compile(mode)
strMatch = pattern.findall(content)
size = len(strMatch)
targetDir = output + url.split("/")[6] + url.split("/")[7];
try:
os.makedirs(targetDir)
except Exception,e:
pass
for i in range(0,size,1):
fileName = strMatch[i]
partIndex = fileName.rfind('/')
if fileName.startswith('http://'):
fileOutput = targetDir +fileName[partIndex:]
print fileOutput
Download(fileName,fileOutput)
def Action(url):
request = urllib2.Request(url)
response = urllib2.urlopen(request)
content = response.read()
mode = '\'([^\']+'+"html"+')\''
pattern = re.compile(mode)
strMatch = pattern.findall(content)
size = len(strMatch)
lenth = 0
for i in range(0,size,1):
one = strMatch[i]
if not (one.startswith("/html/yinlegushihui/magazine/2016") or
one.startswith("/html/yinlegushihui/magazine/2015") or
one.startswith("/html/yinlegushihui/magazine/2014") or
one.startswith("/html/yinlegushihui/magazine/2013") or
one.startswith("/html/yinlegushihui/magazine/2012") or
one.startswith("/html/yinlegushihui/magazine/2011")):
continue
lenth = lenth + 1
print "amount:" + str(lenth)
for i in range(0,size,1):
one = strMatch[i]
if not (one.startswith("/html/yinlegushihui/magazine/2016") or
one.startswith("/html/yinlegushihui/magazine/2015") or
one.startswith("/html/yinlegushihui/magazine/2014") or
one.startswith("/html/yinlegushihui/magazine/2013") or
one.startswith("/html/yinlegushihui/magazine/2012") or
one.startswith("/html/yinlegushihui/magazine/2011")):
continue
UrlItem = "http://www.qnwz.cn" + one
DownloadMP3(UrlItem)
print "remain:" + str(lenth - i - 1)
if __name__=='__main__':
print "download"
url = "http://www.qnwz.cn/html/yinlegushihui/magazine/list_259_3.html";
Action(url);