python爬虫下载bt天堂种子文件
python备忘
#-*-coding:utf8-*-
from multiprocessing.dummy import Pool as ThreadPool
import urllib2
import urllib
import requests
import time,re
import random
def downimg(dd):
print "正在下载中---------------"
data = {}
data['action'] = 'download'
data['id'] = dd[0]
data['uhash'] = dd[1]
url = 'http://www.bttiantang.cc/download2.php'
post_data = urllib.urlencode(data)
req = urllib2.urlopen(url, post_data)
content = req.read()
fp = open('images/'+urllib.unquote(dd[0])+'.torrent', 'wb')
fp.write(content)
fp.close()
def downzhognzi(url):
r = requests.get(url)
html = r.content
e = re.findall("<div class=\"tinfo\">\r\n<a href=\"(.*?)\" title", html)
dd = []
if len(e) > 0:
str11 = e[0]
for key_value in str11.split('&'):
temp = key_value.split('=')
if temp[0] == 'id':
dd.append(temp[1])
if temp[0] == 'uhash':
dd.append(temp[1])
if len(dd) == 2:
downimg(dd)
dd = []
for i in range(28000,28093):
dd.append("http://www.bttiantang.com/subject/"+str(i)+".html")
pool = ThreadPool(10)
results = pool.map(downzhognzi,dd)
pool.close()
pool.join()
