Python批量下载豆瓣妹子的图片
2018-07-20 来源:open-open
[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("哈哈,妹子图片下载完毕啦!")
标签: 代码
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
下一篇:Python计算文件大小
最新资讯
热门推荐