2019独角兽企业重金招聘Python工程师标准>>>

  1. 安装python 3.4.2
  2. 安装相关的库:
  3. pip install beautifulsoup4pip install threadpool
  4. #!/usr/bin/python
    #fileencoding:utf-8
    '''
    EXCEL DATA ANALYSIS
    Created on 2016年08月09日
    '''
    import threadpool
    from bs4 import BeautifulSoup
    import os
    #当前目录
    BASE_DIR = os.path.split(os.path.realpath(__file__))[0]
    #起始和结束页
    begin_page  = 1
    endindex = 5
    #分辨率
    scale = "2560x1600"
    base_page_url = "http://wallpaperswide.com/page/"
    base_url = "http://wallpaperswide.com"
    import urllib.request
    import socket
    #测试进行一页
    def main(page):socket.setdefaulttimeout(20)#http://wallpaperswide.com/page/2response = urllib.request.urlopen(base_page_url+str(page))html = response.read().decode('utf-8',"ignore")soup = BeautifulSoup(html,"html.parser")url_list = []for ul in soup.select("ul.wallpapers"):for a in ul.select("a"):url_list.append(a.get('href'))#print (url_list)list_target = []if url_list:for item in url_list:response = urllib.request.urlopen(base_url+item)html = response.read().decode('utf-8',"ignore")soup1 = BeautifulSoup(html,"html.parser")for div in soup1.select("div.wallpaper-resolutions"):for target_a in div.select("a"):if target_a.string == scale:list_target.append(base_url+target_a.get('href'))for img_url in list_target:imgName = img_url[img_url.rindex("/")+1:]#targetDir = os.path.join(BASE_DIR,"2560x1600")#targetPath = os.path.join(targetDir,imgName)#urllib.urlretrieve(dowloadUrl, targetPath)header = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64)\AppleWebKit/537.36 (KHTML, like Gecko)\Chrome/35.0.1916.114 Safari/537.36','Cookie': 'AspxAutoDetectCookieSupport=1'}request = urllib.request.Request(img_url, None, header)target_path = os.path.join(BASE_DIR,"2560x1600")if not os.path.exists(target_path):os.makedirs(target_path)targetDir = os.path.join(target_path,imgName)response = urllib.request.urlopen(request)#print response.headers['Content-Length']with open(targetDir,"wb") as f:f.write(response.read())print ("page %s" % page)print ("dowload %s ok" % img_url)
    def print_now(request, n):print ('%s - %s' % (request.requestID, n))
    if __name__ == "__main__":if not type(begin_page) == type(1) or not type(endindex) == type(1) or not begin_page <endindex:print("开始和结束页必须为整数,且开始页必须小于结束页")else:pool = threadpool.ThreadPool(50)requests = threadpool.makeRequests(main, range(begin_page,endindex+1), print_now)[pool.putRequest(req) for req in requests]pool.wait()

转载于:https://my.oschina.net/yangting880815/blog/730075

python脚本多线程爬虫爬电脑壁纸相关推荐

  1. python爬取百度贴吧中的所有邮箱_使用 Python 编写多线程爬虫抓取百度贴吧邮箱与手机号...

    原标题:使用 Python 编写多线程爬虫抓取百度贴吧邮箱与手机号 不知道大家过年都是怎么过的,反正栏主是在家睡了一天,醒来的时候登QQ发现有人找我要一份贴吧爬虫的源代码,想起之前练手的时候写过一个抓 ...

  2. python爬电影_使用Python多线程爬虫爬取电影天堂资源

    最近花些时间学习了一下Python,并写了一个多线程的爬虫程序来获取电影天堂上资源的迅雷下载地址,代码已经上传到GitHub上了,需要的同学可以自行下载.刚开始学习python希望可以获得宝贵的意见. ...

  3. python多线程爬虫实例-Python实现多线程爬虫

    编辑推荐: 本文主要介绍对Python多线程爬虫实战的整体的思路,希望对大家有帮助. 本文来知乎,由火龙果软件Alice编辑,推荐. 最近在写爬虫程序爬取亚马逊上的评论信息,因此也自学了很多爬虫相关的 ...

  4. python + selenium +pyquery 爬虫 爬取 1688详情图片 阿里巴巴详情图片 与标题 下载图片并进行压缩

    python + selenium +pyquery 爬虫  爬取 1688详情图片 阿里巴巴详情图片 与标题 下载图片并进行压缩 用到的库和源码下载地址 需要用到chromedriver  包含wi ...

  5. python远程控制电脑_只需一个python脚本就可远程控制电脑,打开微信即可远程遥控操作...

    原标题:只需一个python脚本就可远程控制电脑,打开微信即可远程遥控操作 今天带给大家一个非常有意思的 python 程序,基于 itchat 实现微信控制电脑.你可以通过在微信发送命令,来拍摄当前 ...

  6. python简单网站爬虫-爬取北京7天最高、最低气温

    python简单网站爬虫-爬取北京7天最高.最低气温 前置操作: 1.待爬取网站: 北京天气的网址: http://www.weather.com.cn/weather1d/101010100.sht ...

  7. Python秀操作 自动更换电脑壁纸

    文章目录 一.前言 二.获取壁纸 1. 分析网页 2. 爬虫基本思路 3. Python代码实现 三.自动更换壁纸 四.打包成exe 原文链接:https://yetingyun.blog.csdn. ...

  8. python简单爬虫手机号_使用Python编写多线程爬虫抓取邮箱与手机号(2)

    我们的爬虫抓取数据本质上就是不停的发起http请求,获取http响应,将其存入我们的电脑中.了解http协议有助于我们在抓取数据的时候对一些能够加速抓取速度的参数能够精准的控制,比如说keep-ali ...

  9. python queue查询空_【Python】多线程爬虫案例

    爬取博客园文章列表 爬取博客园文章列表,假设页面的URL是https://www.cnblogs.com/loaderman 要求:使用requests获取页面信息,用XPath / re 做数据提取 ...

最新文章

  1. ES6笔记(4)-- Symbol类型
  2. leetcode之Count and Say报数
  3. Mysql中的行级锁、表级锁、页级锁
  4. [Redux/Mobx] 什么是redux?说说你对redux的理解?有哪些运用场景?
  5. 前端技术周刊 2019-01-21:跨端开发的三条路线
  6. 文件夹_【教程】创建透明文件夹(非隐藏文件夹哦)
  7. c#hello world_C#| 打印消息/文本(用于打印Hello world的程序)
  8. 这个AI狠!能互译C++、Java和Python,以后只学一种编程就行吗
  9. 性能测试工具JMeter的安装及环境配置--Windows和Linux
  10. 命令行中,变量 date time 格式化设定
  11. 计算机被格式化怎么找回资料,电脑文档被格式化,怎么恢复格式化文档
  12. unity 编辑器 混合使用固定布局和自动布局(二)
  13. 免疫算法的c语言,免疫算法(IA)
  14. orcadcapture安装_电路原理图设计软件(OrCAD Capture CIS 中文版) 16.6 免费安装版
  15. MSP430F149的看门狗定时器
  16. html5仿ios底部菜单栏,仿苹果电脑任务栏菜单
  17. doxygen的特定命令
  18. RAID10磁盘阵列损坏修复操作
  19. Linux之禅道安装
  20. 人工智能没成果,年底的PPT怎么写?腾讯科学家张潼离职的后续讨论

热门文章

  1. CNN边缘检测--Richer Convolutional Features for Edge Detection
  2. 在Ubuntu16.04上安装CUDA
  3. Linux 常用小技巧
  4. c++ vector向量直接赋值_vector-Jacobian product 解释 ---- pytorch autograd
  5. JAVA里tokens意思_Java TokenMetadata.sortedTokens方法代码示例
  6. liunx使用ssh免密登录
  7. Feign Client的各种超时时间设置
  8. [Spring 深度解析]第4章 Spring之AOP
  9. Tomcat(二):tomcat配置文件server.xml详解和部署简介
  10. Xcode真机调试(有证书)