python3 抓取网页自有图片
2017-07-18 14:54
393 查看
抓包这种事情,要先了解html的dom结果,再去分享如何正则拿到你想要的数据数组,这一步懂了之后才可以执行下面的操作,分享页面元素这事,本文就不再探讨了,想了解如何学习html的,请看博客下,从零学习html的专栏。
抓包程序如下:
抓包程序如下:
import urllib.request import re import time url = 'http://image.baidu.com' req = urllib.request.Request(url, headers={ 'Connection': 'Keep-Alive', 'Accept': 'text/html, application/xhtml+xml, */*', 'Accept-Language': 'en-US,en;q=0.8,zh-Hans-CN;q=0.5,zh-Hans;q=0.3', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko' }) def get_html(): page = urllib.request.urlopen(req) _html = page.read() print(_html.decode('utf-8')) return _html def get_img(_html): reg = 'src="([^ >]+\.(?:jpeg|jpg))"' img_re = re.compile(reg) _html = _html.decode('utf-8') img_list = re.findall(img_re, _html) _time = time.time() x = 0 for img_url in img_list: #随机生成文件名称 _time = _time + x #保存文件到指定文件夹 urllib.request.urlretrieve(img_url, '/Users/jinx/Downloads/img/%s.jpg' % _time) x += 1 return x html = get_html() print(get_img(html))
相关文章推荐
- Python实现简单网页图片抓取完整代码实例
- python 网页抓取并保存图片
- Python之多线程爬虫抓取网页图片的示例代码
- python抓取网页中的图片示例
- Python3 抓取网页中的图片
- python 解析网页,将抓取到的图片保存到本地
- Python爬虫之网页图片抓取的方法
- python抓取网页图片
- Python初学者好玩案例(一):最短的抓取网页图片代码,只有10行
- python抓取网页图片并放到指定文件夹
- 黄聪:python访问抓取网页常用命令(保存图片到本地、模拟POST、GET、中文编码问题)
- python抓取网页中图片并保存到本地
- Python -- 网络编程 -- 抓取网页图片 -- 图虫网
- python抓取网页中图片并保存到本地
- Python爬虫实现抓取网页图片
- 利用python正则表达式抓取网页中的图片到本地
- python抓取网页中图片并保存到本地
- Python抓取网页中的图片到本地
- Python之BeautifulSoup学习之一 粗略抓取网页图片连接地址
- 第一个python程序,小爬虫--抓取网页图片