coding utf-8 import re urllib time def kn book url while not url try k

 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
# -*- coding: utf-8 -*-
import re, urllib, time
def kn(book):
url=''
while not url:
try:
kn1 = urllib.urlopen('http://flibusta.net/' + book)
url = kn1.geturl()
time.sleep(1)
print "get %s" % book
except: print "Can't get %s" % book
return url
if __name__ == '__main__':
conf = open('config.txt', 'r')
list_url = conf.readlines()
conf.close()
res = open('urls.txt','w')
for url in list_url:
print "Getting URL's from %s" % url.strip()
r = urllib.urlopen(url).read()
books = re.findall('<a href=/(b/\d+/download)>', r)
books += re.findall('<a href=/(b/\d+/fb2)>', r)
books = map(kn, books)
res.write('\n'.join(books)+'\n')
res.close()
raw_input('Press any key...')