网页flash图片抓取器( 【每日一题】2018年01月29日一下本文实例)

优采云 发布时间: 2022-02-19 00:03

  网页flash图片抓取器(

【每日一题】2018年01月29日一下本文实例)

  python抓取网页中链接的静态图片

  更新时间:2018-01-29 11:45:46 作者:zoujm-hust12

  这篇文章主要详细介绍python爬取网页中链接的静态图片,有一定的参考价值。有兴趣的朋友可以参考一下。

  本文示例分享了python爬取网页中链接的静态图片的具体代码,供大家参考。具体内容如下

<p># -*- 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标签的数据,输出格式为

0 个评论

要回复文章请先登录注册


官方客服QQ群

微信人工客服

QQ人工客服


线