s6tu
# -*- 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的更多相关文章
- 15. Go 语言“避坑”与技巧
Go 语言"避坑"与技巧 任何编程语言都不是完美的,Go 语言也是如此.Go 语言的某些特性在使用时如果不注意,也会造成一些错误,我们习惯上将这些造成错误的设计称为"坑& ...
随机推荐
- Jmeter JDBC请求-----数据库读取数据进行参数化 通过SSH跳板机连接数据库
前期准备: jdbc驱动:mysql-connector-java-5.1.7-bin.jar Jmeter 要链接MySQL数据库,首选需要下载mysql jdbc驱动包(注:驱动包的版本一定要与你 ...
- 【ABAP系列】SAP ABAP解析XML的示例程序
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP解析XML的示例 ...
- day17跨文件夹导入模块,模块的两种被执行方式,包,直接使用包中模块,包的管理
复习 ''' 1.模块 -- 一系列功能的集合体,用文件来管理一系列有联系的功能,该文件我们称之为模块,文件名就是模块名 -- import | from...import 来导入模块,从而使用模块中 ...
- JavaScript FSO属性大全
什么是FSO? FSO 即 File System Object 文件系统对象,是一种列表 Windows 磁盘目录和文件,对目录和文件进行删除.新建.复制.剪切.移动等操作的技术.使用 FSO 网站 ...
- solr 安装与配置
1. Solr安装与配置 1.1什么是Solr 大多数搜索引擎应用都必须具有某种搜索功能,问题是搜索功能往往是巨大的资源消耗并且它们由于沉重的数据库加载而拖垮你的应用的性能. 这就是为什么转移负载到一 ...
- Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论
Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...
- javascript(DOM)实例
JavaScript学习笔记 JS补充笔记 实例之跑马灯,函数创建.通过ID获取标签及内部的值,字符串的获取与拼接.定时器的使用 使用定时器实现在console中打印内容 Dom选择器使用与调试记录 ...
- HashMap对象转换为JavaBean对象
问题: 在日常代码中,使用 spring包中的 BeanUtils.copyProperties(source,target),可以将A对象的属性复制到B对象中,但是有个问题 无法将HashMap中的 ...
- Node 12 值得关注的新特性
前言 时隔一年,Node.js 12 如约而至,正式发布第一个 Current 版本. 该版本带来了诸如: V8 更新带来好多不错的特性. HTTP 解析速度提升. 启动速度大幅提升. 更好的诊断报告 ...
- ReactiveCocoa 之 优雅的 RACCommand
RACCommand 是一个在 ReactiveCocoa 中比较复杂的类,大多数使用 ReactiveCocoa 的人,尤其是初学者并不会经常使用它. 在很多情况下,虽然使用 RACSignal 和 ...