python requests库爬取网页小实例:爬取网页图片
爬取网页图片:
#网络图片爬取
import requests
import os
root="C://Users//Lenovo//Desktop//"
#以原文件名作为保存的文件名
path=root+url.split("/")[-1]
url="http://placekitten.com/g/500/600"
try:
#如果路径不存在,则创建
if not os.path.exists(root):
os.mkdir(root)
if not os.path.exists(path):
r=requests.get(url)
#将爬取的二进制信息保存为文件(图片)
with open(path,'wb') as f:
f.write(r.content)
f.close()
print("文件保存成功“)
else:
print("文件已存在")
except:
print("爬取失败")
r=requests.get(url)
python requests库爬取网页小实例:爬取网页图片的更多相关文章
- Python:requests库、BeautifulSoup4库的基本使用(实现简单的网络爬虫)
Python:requests库.BeautifulSoup4库的基本使用(实现简单的网络爬虫) 一.requests库的基本使用 requests是python语言编写的简单易用的HTTP库,使用起 ...
- 使用python requests库写接口自动化测试--记录学习过程中遇到的坑(1)
一直听说python requests库对于接口自动化测试特别合适,但由于自身代码基础薄弱,一直没有实践: 这次赶上公司项目需要,同事小伙伴们一起学习写接口自动化脚本,听起来特别给力,赶紧实践一把: ...
- 大概看了一天python request源码。写下python requests库发送 get,post请求大概过程。
python requests库发送请求时,比如get请求,大概过程. 一.发起get请求过程:调用requests.get(url,**kwargs)-->request('get', url ...
- python requests库学习笔记(上)
尊重博客园原创精神,请勿转载! requests库官方使用手册地址:http://www.python-requests.org/en/master/:中文使用手册地址:http://cn.pytho ...
- Python——Requests库的开发者接口
本文介绍 Python Requests 库的开发者接口,主要内容包括: 目录 一.主要接口 1. requests.request() 2. requests.head().get().post() ...
- Python requests库的使用(一)
requests库官方使用手册地址:http://www.python-requests.org/en/master/:中文使用手册地址:http://cn.python-requests.org/z ...
- Python Requests库入门——应用实例-百度、360搜索关键词提交
百度的关键词接口: http://www.baidu.com/s?wd=keyword 360的关键词接口: http://www.so.com/s?q=keyword keyword就是需要查找的关 ...
- python requests库学习笔记(下)
1.请求异常处理 请求异常类型: 请求超时处理(timeout): 实现代码: import requestsfrom requests import exceptions #引入exc ...
- Python Requests库简单入门
我对Python网络爬虫的学习主要是基于中国慕课网上嵩天老师的讲授,写博客的目的是为了更好触类旁通,并且作为学习笔记之后复习回顾. 1.引言 requests 库是一个简洁且简单的处理HTTP请求的第 ...
随机推荐
- 【Python爬虫】01:网络爬虫--规则
Python网络爬虫与信息提取 目标:掌握定向网络数据爬取和网页解析的基本能力. the website is the API 课程分为以下部分: 1.requsets库(自动爬取HTML页面.自动网 ...
- flutter 访问网页+http请求
一.目录 1.访问网页 2.http请求 -----------------------------这是分割线----------------------------- 1.访问网页 基于url_la ...
- C#压缩文件,C#压缩文件夹,C#获取文件
using System; using System.Data; using System.Configuration; using System.Collections.Generic; using ...
- HTML5+CSS3(2)
一.视频与音频 1.用JavaScript检测音频格式支持 <!DOCTYPE html> <html> <head> <meta charset=" ...
- c#switch语句的用法
switch条件语句是一种很常用的选择语句,它与if条件语句不同,它只针对某个表达式的值作出判断,从而决定执行哪一段代码. switch条件语句用到的关键字: switch case break de ...
- Programming Series 1.0 — C Programming
In the growing world of technology, C programming has kind of lost its way. Today, we have a million ...
- 运行UMAT:+ABQ和VS、IVF绑定
运行UMAT: 1.run-script----xxxx.py2.属性---编辑材料---通用---非独立变量---用户材料3.job---编辑作业---通用----用户子程序.for4.parall ...
- Eclipse在开发JavaEE时怎么显示隐藏的WebContent和build文件夹
在使用eclipse是WebContent和build文件被隐藏起来时解决方法: 1.选择eclipse中的下三角选择Select Working Set: 2.将Java Main Sources选 ...
- jsTree通过AJAX从后台获取数据
页面代码: <div id="MenuTree"></div> javascript代码: $(document).ready(function ($) { ...
- <Dare To Dream>团队项目用户验收评审
实验十二 团队作业8—团队项目用户验收评审 任务1:团队作业Beta冲刺 Beta冲刺第一天:http://www.cnblogs.com/Dare-To-Dream/p/9226994.html B ...