这是个比较简单的入门爬虫。基于python3。

urllib,urllib2,python3中用urllib.request代替,使用方法基本一致。

 #python3
import urllib.request
import time
import re
import random
def getHtml(url):
     #添加User_agent,头信息,伪装成浏览器请求。
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
req = urllib.request.Request(url=url, headers=headers)
page = urllib.request.urlopen(req)
html = page.read()
return html def getImage(html):
html = html.decode('utf-8')
imageList = re.findall(r'src="(.*?\.(jpg|png))"',html)
x = 1
for imageUrl in imageList:
urllib.request.urlretrieve(imageUrl[0],'/home/hang/pythonLearning/Crawler/CrawlDouyuGirl/%d.%s'%(x,imageUrl[1]))
print("已下载:%s" % imageUrl[0])
x += 1
temp = random.randint(3,7)
time.sleep(temp) html = getHtml("https://www.douyu.com/directory/game/yz") getImage(html)

入门娱乐用,没太多技术含量,莫嘲笑。

最新文章

  1. linux 防火墙配置
  2. SSH三大框架合辑的搭建步骤
  3. Android的进程和线程(转)
  4. BZOJ 1833 ZJOI2010 count 数字计数 数位DP
  5. python初探-数据类型
  6. Google Code Jam Round 1C 2015 Problem A. Brattleship
  7. js加强版图片轮播
  8. iOS tableViewCell 在自定义高度方法中遇到的问题,cell高度为0,cell显示不出来,cell直接显示第几个而不是...cell显示个数不对
  9. POJ2398【判断点在直线哪一侧+二分查找区间】
  10. AJAX发送PUT请求引发的血案
  11. 关系数据库数据与hadoop数据进行转换的工具 - Sqoop
  12. webpack项目打包配置
  13. java基础要点总结
  14. spring cloud实战与思考(一) spring config全局配置方案设计
  15. scrapy xpath、正则表达式、css选择器
  16. Android Monkey压力测试环境搭建及使用
  17. LeetCode--155--最小栈(java版)
  18. 2019.3.22 Week 11 : ZigBee power test and field test
  19. HTML5纯Web前端也能开发直播,不用开发服务器(使用face2face)
  20. [hdu3685]Rotational Painting 凸包 重心

热门文章

  1. HDU 1880 题解(字符串哈希)
  2. mysql自动备份脚本
  3. Oracle DBA_EXTENTS视图 与 DBA_SEGMENTS视图
  4. controller函数中参数列表使用多个@RequestBody
  5. Tomcat 8.5 apr 模式配置
  6. org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [dx.service.ItemService] found for dependency
  7. nativescript(angular2)——ListView组件
  8. jsp基础模板
  9. win7系统安装sql2000数据库时没有反应,不出来安装界面?
  10. gawk进阶