玩蛇网提供最新Python编程技术信息以及Python资源下载!
您现在的位置: 玩蛇网首页 > Python源码实例 > 正文内容

python3 bs4 抓取豆瓣MM图片

python3 bs4 抓取豆瓣MM图片

python 3.3 + BeautifulSoup
 
 

 

1. [代码]python3 bs4 抓取豆瓣MM图片 [Python]代码

#!/usr/bin/env python
import urllib.request
from bs4 import BeautifulSoup

def crawl(url):
    headers = {'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'}
    req = urllib.request.Request(url, headers=headers)
    page = urllib.request.urlopen(req, timeout=20)
    contents = page.read()
    soup = BeautifulSoup(contents)
    my_girl = soup.find_all('img')
    for girl in my_girl:
        link = girl.get('src')
        print(link)
        content2 = urllib.request.urlopen(link).read()
        with open(u'D:\doubanmeizi'+'/'+link[-11:],'wb') as code:
            code.write(content2)

page_start = 0
page_stop = 10
for page in range(page_start, page_stop):
    page += 1
    url = 'http://www.dbmeinv.com/?pager_offset=%s' % page
    crawl(url)

print("玩蛇python之家提示, MM图片下载完毕。!")

玩蛇网文章,转载请注明出处和文章网址:http://www.iplaypy.com/code/c331.html

相关文章 Recommend

玩蛇网Python互助QQ群,欢迎加入-->: 106381465 玩蛇网Python新手群
修订日期:2017年01月04日 - 11时40分23秒 发布自玩蛇网

我要分享到:

必知PYTHON教程 Must Know PYTHON Tutorials

必知PYTHON模块 Must Know PYTHON Modules