鱼C论坛

 找回密码
 立即注册
查看: 5189|回复: 3

[原创] 哈哈哈哈,分享一下我的爬虫小分队.

[复制链接]
发表于 2017-9-11 14:23:18 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 神奇的yxq 于 2017-10-20 12:21 编辑

学完小甲鱼的爬虫教程,迫不及待的写了几个爬虫~

爬虫功能:爬取电影资源

py版本:3.6.2

放源码:

1、主爬虫代码:

  1. #爬虫名称:movies爬
  2. #爬虫功能:爬取电影资源,生成一个html文本
  3. #爬虫版本:1.0
  4. #作者:yangxq
  5. #时间:2017.09.10

  6. import sys
  7. sys.path.append('E:\LearnCode\python\MyMod')
  8. import re
  9. import random
  10. import gethtml
  11. import time
  12. import savehtml

  13. #主函数
  14. def main():
  15.     target = 'http://www.mp4ba.net/'

  16.     #需要爬取的页数
  17.     pages = 10
  18.    
  19.     #逐页爬取电影
  20.     for i in range(1,pages + 1):
  21.         
  22.         #拼接每页的地址
  23.         pageurl = target + 'forum-mp4ba-' + str(i) +'.html'
  24.         
  25.         #获取第i页的电影列表
  26.         code,html = gethtml.gethtml(pageurl)
  27.         html = html.decode(code)
  28.         
  29.         print('\n正在访问第 %d/10页 : %s\n' % (i,pageurl) + '-' * 50)
  30.         movies_name,movies_url = getmovies(html)
  31.         num = len(movies_name)

  32.         info = []
  33.         #获取每个电影的磁力链接
  34.         for j in range(num):
  35.             print('\n第%d页 %d/%d | 正在爬取 %s 的详情页...' % (i,j + 1,num,movies_name[j]))
  36.             code,html = gethtml.gethtml(movies_url[j])
  37.             html = html.decode(code)
  38.             movies_summary,magnet= getmagnet(html)
  39.             print('\n%s 的资源已经爬取!正在赶往下一个网页...' % movies_name[j] + '\n' * 2 + '-' * 30 )

  40.             temp = []
  41.             #电影信息打包处理
  42.             temp.append(movies_summary)
  43.             for each in magnet:
  44.                 temp.append(magnet)
  45.             info.append(temp)

  46.         #按页保存到html文件
  47.         savehtml.savehtml(movies_name,movies_url,info)

  48. #获取页面电影链接
  49. def getmovies(html):
  50.     movies_name = []
  51.     movies_url = []

  52.     start = 10
  53.     #循环查找电影名称和链接
  54.     while True:
  55.         
  56.         #页面上电影名称开始特征'xst' 结束特征'<'
  57.         start = html.find('xst',start)
  58.         #当查找不到xst时退出循环
  59.         if start == -1:
  60.             break
  61.         end = html.find('<',start + 5)
  62.         print('\n已找到 : %s' % html[start + 5:end])
  63.         movies_name.append(html[start + 5:end])

  64.         #电影详情网址链接在'xst'之前第一个'href'之后 结束特征'"'
  65.         begin = html.find('href=',start - 100)
  66.         stop = html.find('"',begin + 6)
  67.         movies_url.append(html[begin + 6:stop])

  68.         #进入下一个查找段
  69.         start += 100
  70.    
  71.     #返回主页上的电影的网址列表
  72.     num = len(movies_name)
  73.     print('\n本页查找完毕!       共发现电影 %s 部\n' %num + '-' * 50)
  74.     return (movies_name,movies_url)

  75. #获取磁力链接
  76. def getmagnet(html):
  77.     magnet = []

  78.     #查找简介 特征'简介' 结束特征'<'
  79.     start = html.find('◎简  介')
  80.     end = html.find('<div',start + 10)
  81.     movies_summary = html[start + 12:end - 1]

  82.     #删除错误截取的html代码
  83.     div = movies_summary.find('div')
  84.     movies_summary = movies_summary[0:start - 2]

  85.     print('\n  简介:\n%s' % movies_summary)
  86.    
  87.     #循环查找磁链
  88.     end = 0
  89.     while True:

  90.         #磁链开始特征'magnet:?' 结束标志'<'
  91.         start = html.find('magnet:?',end)
  92.         #当查找不到'magnet:?'时退出循环
  93.         if start == -1:
  94.             if len(magnet) == 0:
  95.                 magnet.append('http://www.mp4ba.net/')   
  96.             break
  97.         end = html.find('>',start)
  98.         print('\n  磁力:%s' % html[start:end])
  99.         magnet.append(html[start:end])
  100.         #进入下一个查找段

  101.     #返回磁力链接列表
  102.     return (movies_summary,magnet)
  103.         
  104. if __name__ == '__main__':
  105.     print('\n爬虫开始工作...')
  106.     main()

复制代码


因为需要写入到html文件,所有单独写了一个功能为保存为html的单独代码
2、保存功能的代码:

  1. import time

  2. def savehtml(movies_name,movies_url,info):
  3.    
  4.     htmlinit = '''<!doctype html><html lang="zh-cn" ><head><meta charset="GBK"><title>MoviesList</title></head><body><h3 align="center" id="1">欢迎使用yangxq的电影爬虫</h3><h6 align="center"><stong>Yangxq</stong></h6><hr><hr>'''
  5.     localtime = time.localtime()
  6.    
  7.     htmlname = 'MoviesList'      + '_' + \
  8.                str(localtime[0]) + '_' + \
  9.                str(localtime[1]) + '_' + \
  10.                str(localtime[2]) +  '.html'
  11.    
  12.     with open(htmlname,'a+') as f:
  13.         #将文件指针指向第一个字符
  14.         f.seek(0,0)
  15.         html = f.read()

  16.         #第一次写入初始化
  17.         if '<!doctype' not in html:
  18.              f.seek(0,0)
  19.              f.write(htmlinit)
  20.         
  21.         #不是第一次写入则删除尾部结束代码
  22.         if '</p></body></html>' in html:
  23.             tel = html.find('</p></body></html>')
  24.             f.seek(tel,0)
  25.         
  26.         #按格式写入文件
  27.         num = len(movies_name)
  28.         for i in range(num):
  29.             if movies_name[i] in html:
  30.                 continue
  31.             
  32.             #第一行显示电影名称
  33.             lines1 = '''<p><a target="_blank" href="'''+ movies_url[i] + '''"><big><stong>''' + movies_name[i] + '</stong></big></a><br>' + '-' * 30 + '<br>'
  34.             #第二行显示电影简介
  35.             lines2 = '<i><small>' + info[i][0] + '</small></i><br>' + '-' * 30 + '<br>'
  36.             #第三行显示下载地址
  37.             magnetnum = len(info[i][1])
  38.             lines3 = ''
  39.             for j in range(magnetnum):
  40.                 lines3 = lines3 + '''<a href="'''+ info[i][1][j] + '''">下载地址''' + str(j + 1) + '''</a>     '''

  41.             lines = lines1 + lines2 + lines3 + '<hr>'
  42.             f.write(lines)
  43.         #结束代码
  44.         lines4 = '</p></body></html>'
  45.         f.write(lines4)
  46.         print('\n保存完毕!')

  47. if __name__ == '__main__':
  48.     movies_name=['电影一','电影二']
  49.     info = [['我是电影一的简介',['我是电影一的第一个磁力','我是电影一的第二个磁力']],['我是电影二的简介',['我是电影二的第一个磁力','我是电影二的第二个磁力']]]
  50.     savehtml(movies_name,info)
复制代码



为了提高通用性,把访问代码单独出来了。
3、提供访问功能的代码

  1. import random
  2. import urllib.request
  3. import time
  4. import os


  5. def gethtml(url,data = None):
  6.     #建立地址表和协议表,获取代理ip
  7.     ipadds = []
  8.     iptype = []

  9.     #加上协议
  10.     if 'http://' not in url:
  11.         url = 'http://' + url
  12.    
  13.     #从文件获取ip
  14.     timename = time.localtime()
  15.     ipname = 'iplist_' + str(timename[0]) + '_' +\
  16.                          str(timename[1]) + '_' +\
  17.                          str(timename[2]) + '.txt'

  18.     #不是当天最新的iplist则运行ipget更新
  19.     if ipname not in os.listdir():
  20.         try:
  21.             import ipget
  22.             ipget.main()
  23.             with open(ipname,'r') as ip:
  24.                 iplist = ip.read().split('\n')
  25.                 for each in iplist:
  26.                     iptype.append(each[0:5])
  27.                     ipadds.append(each[8:])
  28.         except ModuleNotFoundError:
  29.             ipadds = ['125.93.148.3:9000','123.7.38.31:9999','220.249.185.178:9999']
  30.             iptype = ['HTTP','HTTP','HTTP']
  31.     else:
  32.         with open(ipname,'r') as ip:
  33.             iplist = ip.read().split('\n')
  34.             for each in iplist:
  35.                 iptype.append(each[0:5])
  36.                 ipadds.append(each[8:])

  37.    
  38.     #代理和伪装
  39.     r = len(ipadds)
  40.     i = int(random.uniform(0,r))
  41.     if __name__ == '__main__':
  42.         print('\n本次访问使用 %s : %s 代理...' % (iptype[i],ipadds[i]))
  43.         
  44.     proxy_support = urllib.request.ProxyHandler({iptype[i]:ipadds[i]})
  45.     opener = urllib.request.build_opener(proxy_support)
  46.     urllib.request.install_opener(opener)

  47.     req = urllib.request.Request(url,data)
  48.     req.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36')
  49.     #req.add_header('Host','www.mmjpg.com')
  50.     #req.add_header('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8')
  51.     #req.add_header('Accept-Encoding','gzip, deflate, sdch')
  52.     #req.add_header('Accept-Language','zh-CN,zh;q=0.8')
  53.     #req.add_header('Cache-Control','max-age=0')
  54.     #req.add_header('Referer','http://www.mmjpg.com/' + str(i))

  55.     #访问
  56.     response = urllib.request.urlopen(req)
  57.     html = response.read()

  58.     #不要太过分,休息1~5秒
  59.     code = codetest(html)
  60.     time.sleep(int(random.uniform(1,6)))
  61.     return (code,html)

  62. #网页编码测试
  63. def codetest(html):
  64.     try:
  65.         html = html.decode('UTF-8')
  66.         return 'UTF-8'
  67.     except UnicodeDecodeError:
  68.         try:
  69.             html = html.decode('GBK')
  70.             return 'GBK'
  71.         except UnicodeDecodeError:
  72.             try:
  73.                 html = html.decode('GB18030')
  74.                 return 'GB18030'
  75.             except UnicodeDecodeError:
  76.                 return 'unknow'

  77.    
  78. if __name__ == '__main__':
  79.     print('请输入测试网址: ',end = '')
  80.     url = input()
  81.     code,html = gethtml(url)
  82.    
  83.     print('\n该网页编码是: %s' % code)
  84.     if code != 'unknow':
  85.         with open(url + '.html','w') as f:
  86.             html = html.decode(code)
  87.             f.write(html)
  88.             print('\n文件写入完毕!')
复制代码



防被封,每天第一次运行上面的gethtml时调用这个获取最新的ip
4、ip爬虫

  1. #爬虫名称:ipget
  2. #爬虫功能:从ip代理网站爬取代理ip并时间保存
  3. #爬虫作者:yangxq
  4. #时间:2017.09.09


  5. import urllib.request
  6. import random
  7. import time
  8. import re

  9. #主函数
  10. def main():
  11.     url = 'http://www.xicidaili.com/'
  12.     code,html = gethtml(url)
  13.     html = html.decode(code)
  14.     iplist = ipfind(html)
  15.     ipsave(iplist)

  16. #查找ip
  17. def ipfind(html):
  18.     iplist = {}
  19.     ip = []
  20.    
  21.     #正则匹配ip,端口和协议
  22.     ipadds = re.findall(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}',html)
  23.    
  24.     ipport = re.findall(r'<td>\d{1,5}</td>',html)
  25.     ipport = re.findall(r'\d{1,5}',str(ipport))
  26.    
  27.     iptype = re.findall(r'<td>HTTPS</td>|<td>HTTP</td>',html)
  28.     iptype = re.findall(r'HTTPS|HTTP',str(iptype))

  29.     #以协议数量为标准得到可用ip数量,去除ss协议的ip
  30.     ipnum = len(iptype)
  31.    
  32.     #拼接ip和端口,并导入字典,ip为键,协议为值
  33.     for i in range(ipnum):
  34.         ipadd = ipadds[i] + ':' + ipport[i]
  35.         ip.append(ipadd)
  36.         iplist[ip[i]] = iptype[i]
  37.         
  38.     ipnum = len(iplist)
  39.     if __name__ == '__main__':
  40.         print('\n已去掉重复ip地址,最终获得ip地址 %d 个' % ipnum)
  41.    
  42.     return iplist

  43. def gethtml(url,data = None):
  44.    
  45.     ipadds = ['125.93.148.3:9000','123.7.38.31:9999','220.249.185.178:9999']
  46.     iptype = ['HTTP','HTTP','HTTP']

  47.     #代理和伪装
  48.     r = len(ipadds)
  49.     i = int(random.uniform(0,r))
  50.     if __name__ == '__main__':
  51.         print('\n本次访问使用 %s : %s 代理...' % (iptype[i],ipadds[i]))
  52.         
  53.     proxy_support = urllib.request.ProxyHandler({iptype[i]:ipadds[i]})
  54.     opener = urllib.request.build_opener(proxy_support)
  55.     urllib.request.install_opener(opener)

  56.     req = urllib.request.Request(url,data)
  57.     req.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36')
  58.     #req.add_header('Host','www.mmjpg.com')
  59.     #req.add_header('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8')
  60.     #req.add_header('Accept-Encoding','gzip, deflate, sdch')
  61.     #req.add_header('Accept-Language','zh-CN,zh;q=0.8')
  62.     #req.add_header('Cache-Control','max-age=0')
  63.     #req.add_header('Referer','http://www.mmjpg.com/' + str(i))

  64.     #访问
  65.     response = urllib.request.urlopen(req)
  66.     html = response.read()

  67.     #不要太过分,休息1~5秒
  68.     code = codetest(html)
  69.     time.sleep(int(random.uniform(1,6)))
  70.     return (code,html)

  71. def codetest(html):
  72.     try:
  73.         html = html.decode('UTF-8')
  74.         return 'UTF-8'
  75.     except UnicodeDecodeError:
  76.         try:
  77.             html = html.decode('GBK')
  78.             return 'GBK'
  79.         except UnicodeDecodeError:
  80.             try:
  81.                 html = html.decode('GB18030')
  82.                 return 'GB18030'
  83.             except UnicodeDecodeError:
  84.                 return 'unknow'
  85.             
  86. #储存
  87. def ipsave(iplist):
  88.     timename = time.localtime()
  89.    
  90.     ipname = 'iplist_' + str(timename[0]) + '_' +\
  91.                          str(timename[1]) + '_' +\
  92.                          str(timename[2]) + '.txt'

  93.     #保存
  94.     with open(ipname,'w') as f:
  95.         for each in iplist:
  96.             f.writelines(iplist[each] + ' : ' + each)
  97.             f.write('\n')
  98.             
  99.     if __name__ == '__main__':
  100.         print('\n所有ip保存完毕!')


  101. if __name__ == '__main__':
  102.     main()
复制代码



新加一个模块,自己写的,以后写爬虫就获取网页这一步就可以省很多事.
internet 模块:

  1. import urllib.request, urllib.parse, urllib.error
  2. import http.cookiejar
  3. import os, os.path
  4. import threading
  5. import random
  6. import queue
  7. import chardet
  8. import time
  9. import mylogging


  10. def urlParse(url):
  11.     if "www" not in url:
  12.         url = "www." + url
  13.     if "http" not in url:
  14.         url = "http://" + url
  15.     return url


  16. class Browse:
  17.     def __init__(self, name="浏览器"):
  18.         self.name = name
  19.         self.cookie = False
  20.         # self.proxy = False
  21.         # self.history = []  # 历史记录
  22.         self.header = {
  23.             "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
  24.             "Accept-Encoding": "utf-8",
  25.             "Accept-Language": "zh-CN,zh;q=0.8",
  26.             "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36",
  27.             "Connection": "keep-alive"}
  28.         # log日记初始化
  29.         self._log_ = mylogging.Logging(logPath="Download", name="浏览器")

  30.     def get(self, url):
  31.         """
  32.         get方法的函数
  33.         :param url: 获取网页的地址
  34.         :return:
  35.         """
  36.         url = urlParse(url)
  37.         req = urllib.request.Request(url, headers=self.header)
  38.         reTest = 0
  39.         loop = True
  40.         while loop:
  41.             if reTest < 3:
  42.                 try:
  43.                     response = urllib.request.urlopen(req)
  44.                 except urllib.error.HTTPError as e:
  45.                     code = reason = "none"
  46.                     if hasattr(e, "code"):
  47.                         code = e.code
  48.                     if hasattr(e, "reason"):
  49.                         reason = e.reason
  50.                     self._log_.put((self.name, "HTTPError %s %s %s" % (url, code, reason)))
  51.                     return "HTTPError"
  52.                 except urllib.error.URLError as e:
  53.                     code = reason = "none"
  54.                     if hasattr(e, "code"):
  55.                         code = e.code
  56.                     if hasattr(e, "reason"):
  57.                         reason = e.reason
  58.                     self._log_.put((self.name, "URLError %s %s %s" % (url, code, reason)))
  59.                     return "URLError"
  60.                 except Exception:
  61.                     reTest += 1
  62.                     time.sleep(1)
  63.                     continue
  64.                 else:
  65.                     content = response.read()
  66.                     encoding = chardet.detect(content)["encoding"]
  67.                     html = content.decode(encoding)
  68.                     self._log_.put((self.name, "Get Html Success! %s" % url))
  69.                     return html
  70.             else:
  71.                 self._log_.put((self.name, "OtherError %s %s %s" % url))
  72.                 return "OtherError"

  73.     def post(self, url, data):
  74.         """
  75.         post方法的函数
  76.         :param url: 网页地址
  77.         :param data: 表单字典
  78.         :return:
  79.         """
  80.         if self.cookie:
  81.             cjar = http.cookiejar.CookieJar()
  82.             opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cjar))
  83.             urllib.request.install_opener(opener)

  84.         # url = urlParse(url)
  85.         postdata = urllib.parse.urlencode(data).encode("utf-8")
  86.         req = urllib.request.Request(url, data=postdata, headers=self.header)

  87.         reTest = 0
  88.         loop = True
  89.         while loop:
  90.             if reTest < 3:
  91.                 try:
  92.                     response = urllib.request.urlopen(req)
  93.                 except urllib.error.HTTPError as e:
  94.                     code = reason = "none"
  95.                     if hasattr(e, "code"):
  96.                         code = e.code
  97.                     if hasattr(e, "reason"):
  98.                         reason = e.reason
  99.                     self._log_.put((self.name, "HTTPError %s %s %s" % (url, code, reason)))
  100.                     return "HTTPError"
  101.                 except urllib.error.URLError as e:
  102.                     code = reason = "none"
  103.                     if hasattr(e, "code"):
  104.                         code = e.code
  105.                     if hasattr(e, "reason"):
  106.                         reason = e.reason
  107.                     self._log_.put((self.name, "URLError %s %s %s" % (url, code, reason)))
  108.                     return "URLError"
  109.                 except Exception:
  110.                     reTest += 1
  111.                     time.sleep(1)
  112.                     continue
  113.                 else:
  114.                     content = response.read()
  115.                     encoding = chardet.detect(content)["encoding"]
  116.                     html = content.decode(encoding)
  117.                     self._log_.put((self.name, "Post Html Success! %s" % url))
  118.                     return html
  119.             else:
  120.                 self._log_.put((self.name, "OtherError %s %s %s" % url))
  121.                 return "OtherError"


  122. class Download(threading.Thread):
  123.     def __init__(self, srcQueue=queue.Queue(), name="下载器"):
  124.         threading.Thread.__init__(self)
  125.         self.name = name  # 进程名称
  126.         self.srcQueue = srcQueue  # 下载队列
  127.         self.sleeptime = 0  # 下载等待时间
  128.         self.Daemon = True  # 设置守护线程
  129.         self.downloadPath = "Download"  # 批量下载路径
  130.         self.srcName = True  # 下载命名方式 自动还是手动?
  131.         self.srcType = "jpg"  # 下载文件的格式
  132.         self.downloadShow = True  # 是否显示下载进度条
  133.         # log立即初始化
  134.         self._log_ = mylogging.Logging(logPath="Download", name="下载器")

  135.     def __reporthook__(self, downloaded, perDataSize, allData):
  136.         """
  137.         用于显示下载进度条
  138.         :param downloaded:已经下载的数据包
  139.         :param perDataSize:每个数据包的大小
  140.         :param allData:文件的总大小
  141.         :return:
  142.         """
  143.         if self.downloadShow:
  144.             downloadedSize = downloaded * perDataSize
  145.             percent = downloadedSize / allData
  146.             if percent > 1:
  147.                 percent = 1
  148.             donePart = int(percent * 50)
  149.             undonePart = 50 - donePart
  150.             line = ">" * donePart + "_" * undonePart
  151.             downloadedSize = downloadedSize / 1024 / 1024  #下载的大小
  152.             alldataSize = allData / 1024 / 1024  #总大小
  153.             print("下载进度[%s%3.2d%%] %.2fMB/%.2fMB" % (line, percent * 100, downloadedSize, alldataSize))
  154.         else:
  155.             pass

  156.     def __getName__(self, count=0):
  157.         """
  158.         获取下载名称
  159.         :param count:
  160.         :return:
  161.         """
  162.         dirList = os.listdir(self.downloadPath)
  163.         while True:
  164.             if self.srcName:  # 下载命名选项
  165.                 name = str(count) + "." + self.srcType
  166.                 count += 1
  167.                 if not os.path.exists(self.downloadPath + "\" + name):
  168.                     break
  169.             else:
  170.                 name = input("请重命名资源下载名称:")
  171.                 break
  172.         return name

  173.     def run(self):
  174.         """
  175.         线程主程序
  176.         :return:
  177.         """
  178.         if not os.path.exists(self.downloadPath):  # 创建下载文件夹
  179.             os.mkdir(self.downloadPath)

  180.         count = 1
  181.         srcUrl = self.srcQueue.get()
  182.         name = self.__getName__(count)

  183.         reTest = 0
  184.         loop = True
  185.         while loop:
  186.             if reTest < 3:
  187.                 try:
  188.                     path = self.downloadPath + "\" + name  # 拼接存放路径及名称
  189.                     print("正在下载:%s [from %s...%s]" % (name, srcUrl[:20], srcUrl[-20:]))
  190.                     urllib.request.urlretrieve(srcUrl, path, self.__reporthook__)
  191.                     print("下载完成:%s [from %s...%s]" % (name, srcUrl[:20], srcUrl[-20:]))
  192.                 except urllib.error.HTTPError as e:
  193.                     code = reason = "none"
  194.                     if hasattr(e, "code"):
  195.                         code = e.code
  196.                     if hasattr(e, "reason"):
  197.                         reason = e.reason
  198.                     self._log_.put((self.name, "HTTPError %s %s %s" % (srcUrl, code, reason)))
  199.                 except urllib.error.URLError as e:
  200.                     code = reason = "none"
  201.                     if hasattr(e, "code"):
  202.                         code = e.code
  203.                     if hasattr(e, "reason"):
  204.                         reason = e.reason
  205.                     self._log_.put((self.name, "URLError %s %s %s" % (srcUrl, code, reason)))
  206.                 except Exception:
  207.                     reTest += 1
  208.                     time.sleep(1)
  209.                     continue
  210.                 else:
  211.                     self._log_.put((self.name, "%s Download Success! %s" % (path, srcUrl)))
  212.             else:
  213.                 self._log_.put((self.name, "otherError %s" % srcUrl))

  214.             reTest = 0
  215.             srcUrl = self.srcQueue.get()
  216.             name = self.__getName__(count)
  217.             time.sleep(random.choice(range(self.sleeptime)))





复制代码


tips:mylogging是我自己的错误立即模块.就不放上来了,其实就是一个put函数获取信息 再写入到相应的文本文件中

评分

参与人数 1荣誉 +1 鱼币 +1 收起 理由
purplenight + 1 + 1 支持楼主!

查看全部评分

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-9-30 16:21:14 | 显示全部楼层
楼主,你这个复制下来是不是就可以用了,用了第三方的模块 没有呀。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-10-4 18:34:10 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2017-10-9 12:53:04 | 显示全部楼层
741712547 发表于 2017-9-30 16:21
楼主,你这个复制下来是不是就可以用了,用了第三方的模块 没有呀。

没有  可以用
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-29 13:23

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表