Python 3 抓取百度贴吧图片

# -*- coding: utf-8 -*-
"""抓取贴吧图片"""

import urllib.request
from bs4 import BeautifulSoup 

def get_content(url):
    """取得页面内容"""
    html = urllib.request.urlopen(url).read()
    data = html.decode("UTF-8")
    return data

def get_image(html_doc):
    """贴吧图片在<img class="BDE_Image" ……> 标签下"""
    soup = BeautifulSoup(html_doc)
    i = 0
    for link in soup.find_all("img","BDE_Image"):
        i = i + 1
        link_img = link.get("src")
        urllib.request.urlretrieve(link_img, "%s.jpg" % i)
        print(link_img)

myurl = "http://tieba.baidu.com/p/3797994694"  
my_html_doc = get_content(myurl)
get_image(my_html_doc)
阅读更多
文章标签: python
个人分类: Pyhon
上一篇Excel VBA 学习笔记(2)
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭