python爬虫 -- 抓取网页中链接的静态图片
2018-01-19 16:34
851 查看
# -*- coding:utf-8 -*- #http://tieba.baidu.com/p/2460150866 #抓取图片地址 from bs4 import BeautifulSoup import urllib.request from time import sleep html_doc = "http://tieba.baidu.com/p/2460150866" def get_image(url): req = urllib.request.Request(url) webpage = urllib.request.urlopen(req) html = webpage.read() soup = BeautifulSoup(html, 'html.parser') #抓取图片地址 #抓取img标签且class为BDE_Image的所有内容 img_src=soup.findAll("img",{'class':'BDE_Image'}) i = 1 for img in img_src: img_url = img.get('src') #抓取src # print(img) req = urllib.request.Request(img_url) u = urllib.request.urlopen(req) data = u.read() with open("AutoCodePng20180119-"+str(i)+".jpg", 'wb') as f: sleep(2) f.write(data) i += 1 def getImg(url): html = urllib.request(url) page = html.read() soup = BeautifulSoup(page, "html.parser") imglist = soup.find_all('img') #发现html中带img标签的数据,输出格式为<img xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,存入集合 lenth = len(imglist) #计算集合的个数 for i in range(lenth): print imglist[i].attrs['src'] #抓取img中属性为src的信息,例如<img src="123456" xxxxxxxxxxxxxxxx,则输出为123456
相关文章推荐
- python抓取网页中链接的静态图片
- Python爬虫实现抓取网页图片
- Python3简单爬虫抓取网页图片
- Python 实现网络爬虫 抓取静态网页【代码】
- 【python】100行代码python爬虫程序,抓取网站图片存储本地(附:中文链接解决)
- Python3简单爬虫抓取网页图片
- python爬虫:不需要登录静态网页抓取
- python抓取网页图片 python爬虫实例
- Python之多线程爬虫抓取网页图片的示例代码
- python爬虫实战(1)抓取网页图片自动保存
- python爬虫一:必应图片(从网页源代码中找出图片链接然后下载)
- Python爬虫学习笔记一:简单网页图片抓取
- Python爬虫学习笔记二:百度贴吧网页图片抓取
- Python使用爬虫爬取静态网页图片的方法详解
- Python爬虫之网页图片抓取的方法
- 【Python3.6爬虫学习记录】(一)爬取简单的静态网页图片
- python抓取网页图片示例(python爬虫)
- Python3简单爬虫抓取网页图片
- Python爬虫---爬取静态网页的图片
- python3 网页爬虫图片下载无效链接处理 try except