美文网首页
Python爬虫学习100练002

Python爬虫学习100练002

作者: 夜雨_87aa | 来源:发表于2018-03-25 14:02 被阅读0次

爬取80s网站2018年电视剧作品主图片

-- coding:utf-8 --

2018年3月25日

下载图片request.urlretrieve(jpg_link, path)

from urllib import request
import re

Python 2.7.9 之后引入了一个新特性当你urllib.urlopen一个 https 的时候会验证一次 SSL 证书

导入证书库

import ssl

禁掉这个证书的要求

context = ssl._create_unverified_context()
picture=[["网址","标题"]]

获取图片地址

def gettupian():
response=request.urlopen(url,context=context)
html=response.read().decode("utf-8")
re_tupian=re.compile(r'<li> <a href=.? title="(.?)">.?<img id.?src="(.*?)" src',re.S)
list=re_tupian.findall(html)
for title,url_tp in list:
url_tp="http:"+url_tp
picture.append([url_tp,title])

下载图片到本地

def xz():
for i in range(1,len(picture)):
request.urlretrieve(picture[i][0],str(i)+".jpg")
for j in range(1,5):
url="https://www.80s.tw/ju/list/---2018-0-g-p%s"%j
gettupian()
print("正在下载第%s页"%j)
xz()
print("下载完毕")

相关文章

  • Python爬虫学习100练002

    爬取80s网站2018年电视剧作品主图片 -- coding:utf-8 -- 2018年3月25日 下载图片r...

  • Python爬虫学习100练001

    爬取菜鸟教程最新文章标题以及查看链接并写入excel文件中 -- coding:utf-8 -- 2018年3月2...

  • Python爬虫学习100练003

    -- coding:utf-8 -- 2018年3月28日 爬取淘宝商品信息存到EXcel from urllib...

  • Python爬虫学习(十六)初窥Scrapy

    Python爬虫学习(一)概述Python爬虫学习(二)urllib基础使用Python爬虫学习(三)urllib...

  • 资料

    Python爬虫系列(一)初期学习爬虫的拾遗与总结(11.4更) Python爬虫学习系列教程 Python爬虫学习手册

  • Python爬虫学习系列教程

    转自: 静觅»Python爬虫学习系列教程 Python爬虫学习系列教程 Python版本:2.7 一、爬虫入门 ...

  • 爬虫入门

    为什么要学习爬虫? Python做爬虫优势 关于Python网络爬虫,我们需要学习的有: 什么是爬虫? 网络爬虫(...

  • Python爬虫学习之小结(一)

    到目前为止,Python爬虫学习已经写了八篇文章,分别是: Python爬虫学习(一)概述Python爬虫学习(二...

  • python爬虫学习-day7-实战

    目录 python爬虫学习-day1 python爬虫学习-day2正则表达式 python爬虫学习-day3-B...

  • Python 基础爬虫目录

    目录 python爬虫学习-day1 python爬虫学习-day2正则表达式 python爬虫学习-day3-B...

网友评论

      本文标题:Python爬虫学习100练002

      本文链接:https://www.haomeiwen.com/subject/bpbhcftx.html