# -*- coding: utf-8 -*-
# @Time : 2018/03/30 15:20
# @Author : cxa
# @File : liuuchnagtu.py
# @Software: PyCharm
import requests
from fake_useragent import UserAgent as UA
from lxml import html
import os
import threading
import traceback
import time
import random
class GetImage():
def __init__(self):
self.url="http://www.s6tu.com/explore/popular/?list=images&sort=likes_desc&page={}"
self.imgpath = "//div[@class='list-item-image fixed-size']/a/img/@src"
self.headers = {
'Accept': 'text/html, application/xhtml+xml, image/jxr, */*',
'Accept - Encoding': 'gzip, deflate',
'Accept-Language': 'zh-Hans-CN, zh-Hans; q=0.5',
'Connection': 'Keep-Alive',
'User-Agent': UA().random,
'Host': 'www.s6tu.com',}
def get_oen_page(self):
try:
os.makedirs("setu",exist_ok=True)
for i in range(1,999):
url=self.url.format(i)
Session=requests.session()
#Session.proxies.update(self.proxies)
req=Session.get(url,headers=self.headers)
if req.status_code==requests.codes.ok:
root=html.fromstring(req.text)
imglist=root.xpath(self.imgpath)
newlist=[i.replace(".md.",".")for i in imglist]
downloadThreads=[]
for i in range(0,len(newlist),int(len(newlist)/3)):
downloadThread = threading.Thread(target=self.getimglist, args=(newlist,i, i + int(len(newlist)/3)))
downloadThreads.append(downloadThread)
downloadThread.start()
for item in downloadThreads:
item.join()
print("get one page over") else:
print("errro")
time.sleep(random.randint(1,5))
except:
print("error,here is details:{}".format(traceback.format_exc()))
def getimglist(self,newlist,start,end):
if end>len(newlist):
end=len(newlist)
for i in range(start,end):
imgurl=newlist[i]
downloadThreads = []
print(imgurl)
req=requests.get(imgurl,headers=self.headers)
with open(os.path.join("setu",os.path.basename(imgurl)),"wb") as fs:
fs.write(req.content) if __name__=="__main__":
GetImage().get_oen_page()
  

  

s6tu的更多相关文章

  1. 15. Go 语言“避坑”与技巧

    Go 语言"避坑"与技巧 任何编程语言都不是完美的,Go 语言也是如此.Go 语言的某些特性在使用时如果不注意,也会造成一些错误,我们习惯上将这些造成错误的设计称为"坑& ...

随机推荐

  1. 宝塔 windows下apache环境下禁止某文件夹内运行PHP脚本、禁止访问文件

    首先我们来看两段对上传目录设置无权限的列子,配置如下: //在宝塔下如用/upload这个路径应用无效,一定要C:/wwwroot/upload才有效果 <Directory "要去掉 ...

  2. glibc升级,解决glib版本过低的问题

    Debian wheezy下的glibc版本为2.13,安装几个软件都运行不了,报以下类似错误:xxxx: /lib/i386-linux-gnu/i686/cmov/libc.so.6: versi ...

  3. UVA-10462.Is There A Second Way Left(Kruskal+次小生成树)

    题目链接 本题大意:这道题用Kruskal较为容易 参考代码: #include <cstdio> #include <cstring> #include <vector ...

  4. e.target与e.currentTarget的区别,事件冒泡与事件捕获 ,事件委托

    e.target与e.currentTarget的区别:https://www.jianshu.com/p/1dd668ccc97a 事件冒泡与事件捕获 :https://www.jianshu.co ...

  5. VirtualStringTree常用类和属性

    重要的类:TBaseVirtualTree = class(TCustomControl)TCustomVirtualStringTree = class(TBaseVirtualTree)TVirt ...

  6. docker私有仓库部署

    首先科普docker几种“仓库”概念,可分为:本地镜像,本地仓库,公有仓库(docker hub) 本地镜像:在把java程序打包成镜像,输出的镜像的位置就是本地镜像 公有仓库:一个叫docker h ...

  7. C# log4net 日志写入到数据库

    原文:C# log4net 日志写入到数据库 效果图: 1:第一步创建SQL表结构   ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ...

  8. maven 打包Scala代码到jar包

    idea的pom.xml文件配置 <dependencies> <dependency> <groupId>org.scala-lang</groupId&g ...

  9. javascript中的对象字面量为啥这么酷

    原文链接 : Why object literals in JavaScript are cool 原文作者 : Dmitri Pavlutin 译者 : neal1991 个人主页:http://n ...

  10. IC设计流程介绍

    芯片设计分为前端设计和后端设计,前端设计(也称逻辑设计)和后端设计(也称物理设计)并没有统一严格的界限,涉及到与工艺有关的设计就是后端设计. 1. 规格制定        芯片规格,也就像功能列表一样 ...