博客
关于我
python爬取图片
阅读量:210 次
发布时间:2019-02-28

本文共 943 字,大约阅读时间需要 3 分钟。

baidu图片打开 ——发现是瀑布流,此时可以改成分页模式

将index改为flip

在这里插入图片描述

在这里插入图片描述

就可以改为分页模式了

在这里插入图片描述

查看网页源代码,查询objURL——最清晰

在这里插入图片描述

打开后续网页url就可以得到图片,获取url后可以requests了

示例

在这里插入图片描述

在这里插入图片描述

此时:只爬取了一张图片,那么通过不同url的切换可以爬取多种图片了

如果图片地址末尾没有jpg可以自己加

在这里插入图片描述

# 思路:拿到目标url 获取网页源码 获取图片url地址 保存图片url ='https://image.baidu.com/search/flip?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=result&fr=&sf=1&fmq=1619608652857_R&pv=&ic=&nc=1&z=&hd=&latest=&copyright=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&sid=&word=%E8%8B%8D%E5%8F%B6'headers ={   'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36'}r =requests.get(url=url,headers=headers)ret=r.textprint(ret)# 获取图片url地址result =re.findall(r'"objURL":"(.*?)"',ret)print(result)for url in result:    # 获取图片的名字    name =url[-10:]    print(name)    with open('图片/'+name+'.jpg','wb')as f:        r =requests.get(url)        f.write(r.content)

就取到了

在这里插入图片描述

注意:由于是瀑布流,所以网页格式有点改变,因此正则出来结果会不同,依然可以爬取不影响结果

转载地址:http://krun.baihongyu.com/

你可能感兴趣的文章
Nginx/Apache反向代理
查看>>
Nginx: 413 – Request Entity Too Large Error and Solution
查看>>
nginx: [emerg] getpwnam(“www”) failed 错误处理方法
查看>>
nginx: [emerg] the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:
查看>>
nginx:Error ./configure: error: the HTTP rewrite module requires the PCRE library
查看>>
Nginx:objs/Makefile:432: recipe for target ‘objs/src/core/ngx_murmurhash.o‘解决方法
查看>>
nginxWebUI runCmd RCE漏洞复现
查看>>
nginx_rtmp
查看>>
Nginx、HAProxy、LVS
查看>>
nginx一些重要配置说明
查看>>
Nginx下配置codeigniter框架方法
查看>>
Nginx与Tengine安装和使用以及配置健康节点检测
查看>>
Nginx中使用expires指令实现配置浏览器缓存
查看>>
Nginx中使用keepalive实现保持上游长连接实现提高吞吐量示例与测试
查看>>
Nginx中实现流量控制(限制给定时间内HTTP请求的数量)示例
查看>>
nginx中配置root和alias的区别
查看>>
nginx主要流程(未完成)
查看>>
Nginx之二:nginx.conf简单配置(参数详解)
查看>>
Nginx从入门到精通
查看>>
Nginx代理websocket配置(解决websocket异常断开连接tcp连接不断问题)
查看>>