软件开发定制python爬取网页图片详解

文章目录

什么是

网络爬虫(软件开发定制又被称为网页蜘蛛,软件开发定制网络机器人)就是模拟浏览器发送网络请求,接收请求响应,一种按照一定的规则,自动地抓取互联网信息的程序。
原则上,只要是浏览器(客户端)能做的事情,爬虫都能够做。

爬取网页图片实现步骤

第一步:打开所操作的网站(任意一个网站)

第二步:通过python访问这个网站

headers = {'User-Agent': 'python-requests/2.25.1', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'}response = requests.get('http://github.com/',headers=headers)print(response.request.headers)
  • 1
  • 2
  • 3

{'User-Agent': 'python-requests/2.25.1', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'}
  • 1

第三步:点击F12查询相关信息


查找到图片信息

获取headers:

第四步:爬取图片,下载到本地

headers = {'User-Agent': 'python-requests/2.25.1', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'}response = requests.get('https://avatars.githubusercontent.com/nplasterer?s=64&v=4',headers=headers)print(response.request.headers)with open('icon.ico', 'wb') as f:    f.write(response.content)    print("爬取图片成功")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

第五步:显示测试

img = cv2.imread("icon.ico")cv2.imshow('icon',img)cv2.waitKey(0)
  • 1
  • 2
  • 3

核心代码

import requestsimport  cv2headers = {'User-Agent': 'python-requests/2.25.1', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'}response = requests.get('https://avatars.githubusercontent.com/nplasterer?s=64&v=4',headers=headers)print(response.request.headers)with open('icon.ico', 'wb') as f:    f.write(response.content)    print("爬取图片成功")img = cv2.imread("icon.ico")cv2.imshow('icon',img)cv2.waitKey(0)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发