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()

2016-05-26 11:28:15

python
python

这是介绍的地方

python的标签

本文相关标签

推荐应用

友情链接


皖ICP备14007051号-2 关于穆子龙