糗图-图片爬取

糗图-图片爬取

主要思路

1.来到首页,查看主页有用图片存在html的规律

2.编写re提取图片路径

3.右键图片查看请求图片的具体路径

4.拼接图片请求路径

5.查看下一页界面的路径,找到界面请求路径规律

6.work,多界面爬取指定图片爬虫

import requests
import re
import os
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
}

def get_page(page_size):
     for i in range(1,page_size+1):
         url = f"https://www.qiushibaike.com/pic/page/{i}/?s=5222080"
         res=requests.get(url=url,headers=headers)
         #解析图片路径
         pic_list=re.findall('<div class="thumb">[\s\S]*?<img src="(.*?)" alt',res.text,re.S)
         for i in pic_list:
             i='https:'+i
             pic_res=requests.get(url=i,headers=headers).content
             file_name=i.split("/")[-1]
             #图片数据写入本地文件夹
             with open(f'pic/{file_name}',"wb")as fw:
                 fw.write(pic_res)
                 print(file_name+"写入成功")

if __name__ == '__main__':
    if not os.path.exists("./pic"):
        os.mkdir("./pic")
    #自定义爬取界面页数
    get_page(3)

原文地址:https://www.cnblogs.com/zx125/p/11404564.html

时间: 2024-07-31 18:37:55

糗图-图片爬取的相关文章

千图网_性感美女图片爬取--图片懒加载

#爬取千图网性感美女模块的图片 #第一页:http://sc.chinaz.com/tupian/xingganmeinvtupian.html #第二页:http://sc.chinaz.com/tupian/xingganmeinvtupian_2.html #两种url结构不同,注意 可以使用if语句判断 import urllib.request import urllib.parse from lxml import etree import time import os #定义下载图

回车桌面图片爬取

回车桌面图片爬取 今天我们就来爬爬这个网站 https://tu.enterdesk.com/ 这个网站能爬的资源还是很多的,但我就写一个例子,其他的可以根据思路去写. 首先还是先来分析下这个网站的图片获取过程 我选择的是图库,先随便选择一个标签,我这选宠物吧 哟,我们再看看有没有翻页 开启F12(开发者工具) 用不习惯火狐,还是开谷歌来看吧 那么就访问看看?随便选取一个访问看看是不是能出图片 https://tu.enterdesk.com/chongwu/6.html 结果肯定是可以的啦 问

Python爬虫入门【2】:妹子图网站爬取

妹子图网站爬取---前言 从今天开始就要撸起袖子,直接写Python爬虫了,学习语言最好的办法就是有目的的进行,所以,接下来我将用10+篇的博客,写爬图片这一件事情.希望可以做好. 为了写好爬虫,我们需要准备一个火狐浏览器,还需要准备抓包工具,抓包工具,我使用的是CentOS自带的tcpdump,加上wireshark ,这两款软件的安装和使用,建议你还是学习一下,后面我们应该会用到. 妹子图网站爬取---网络请求模块requests 妹子图网站爬取---安装requests 打开终端:使用命令

知乎高颜值图片爬取

.katex { display: block; text-align: center; white-space: nowrap; } .katex-display > .katex > .katex-html { display: block; } .katex-display > .katex > .katex-html > .tag { position: absolute; right: 0px; } .katex { font-style: normal; font

Python爬虫新手教程: 知乎文章图片爬取器

1. 知乎文章图片爬取器之二博客背景 昨天写了知乎文章图片爬取器的一部分代码,针对知乎问题的答案json进行了数据抓取,博客中出现了部分写死的内容,今天把那部分信息调整完毕,并且将图片下载完善到代码中去. 首先,需要获取任意知乎的问题,只需要你输入问题的ID,就可以获取相关的页面信息,比如最重要的合计有多少人回答问题.问题ID为如下标红数字 编写代码,下面的代码用来检测用户输入的是否是正确的ID,并且通过拼接URL去获取该问题下面合计有多少答案. import requests import r

scrapy之360图片爬取

#今日目标 **scrapy之360图片爬取** 今天要爬取的是360美女图片,首先分析页面得知网页是动态加载,故需要先找到网页链接规律, 然后调用ImagesPipeline类实现图片爬取 *代码实现* so.py ``` # -*- coding: utf-8 -*- import scrapy import json from ..items import SoItem class SoSpider(scrapy.Spider): name = 'so' allowed_domains =

爬虫07 /scrapy图片爬取、中间件、selenium在scrapy中的应用、CrawlSpider、分布式、增量式

目录 爬虫07 /scrapy图片爬取.中间件.selenium在scrapy中的应用.CrawlSpider.分布式.增量式 1. scrapy图片的爬取/基于管道类实现 2. 中间件的使用 3. selenium在scrapy中的应用 4. CrawlSpider 5. 分布式 5. 增量式 爬虫07 /scrapy图片爬取.中间件.selenium在scrapy中的应用.CrawlSpider.分布式.增量式 1. scrapy图片的爬取/基于管道类实现 爬取流程: 爬虫类中将解析到的图片

[Python_scrapy图片爬取下载]

welcome to myblog Dome地址 爬取某个车站的图片 item.py 中 1.申明item 的fields class PhotoItem(scrapy.Item): # define the fields for your item here like: # name = scrapy.Field() image_urls = scrapy.Field() images = scrapy.Field() pass spider 的image.py 导入头文件 from Phot

python爬虫学习--pixiv爬虫(2)--国际排行榜的图片爬取

之前用面向过程的形式写了一下pixiv爬虫的登录... 觉得还是面向对象好一些... 那就先把登录过程重写一下... class Pixiv_Spider: def __init__(self): self.p_id = '' self.p_pw = '' def Login(self): #处理登录所需要的请求信息 p_login_url = 'https://www.pixiv.net/login.php' data = { #登录所要post的信息 'mode':'login', 'ski