How to download Douban Images Using Python
This example describes how to download a Douban Image Using Python. Share it with you for your reference. The specific analysis is as follows:
1. encapsulate it with tk
2. You can enter the image url by yourself.
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
Download_douban_album #-*-Coding: UTF-8 -*- Import re Import urllib Def count_percent (a, B, c ): Per = 100.0 * a * B/c If per> 100: Per = 100. Print '%. 2f %' % per Def get_url (): N = [x * 18 for x in range (0, 87)] Url_list = [] For I in n: Url = 'HTTP: // www.douban.com/photos/album/73174384 /? Start = % s' % I Url_list.append (url) Return url_list Def get_img_url (): Img_url = [] Url = get_url () For u in url: A = urllib. urlopen (u) For line in a. readlines (): If 'thumb' in line: Img_url.append (line. strip () [10:-4]. replace ('thumb', 'photo ')) Return img_url Def download_img (): Download_url = get_img_url () For u in download_url: Urllib. urlretrieve (u, 'd: \ New \ % s '% u. split ('/') [-1]) If _ name _ = '_ main __': "A = get_img_url () F = open ('d: \ thumb.txt ', 'w ') For I in: # J = I. replace ('thumb', 'photo ') F. write (I + '\ n ') F. close ()""" Download_img () |
I hope this article will help you with Python programming.