Since I obtained images from National Geographic last time, I came up with a new idea: to get photos from tripntale. tripntale is a very good online album, especially for those who prefer traveling.
According to the previous idea of extracting National Geographic photos:
1. Round-Robin of the web page of each photo
The photo album directory structure of tripntale is photo. When you try to access an ID that does not exist in the album, it will automatically jump back to the album, that is, http://www.tripntale.com/trip/8238. The urlopen method of the urllib2 module is used to obtain the response of the page.
Page = urllib2.urlopen ("http://www.tripntale.com/pic/8238/424541 ")
Response = page. Read ()
2. Write a suitable regular expression by studying the image attributes.
By studying the above image, we can get the HTML of the actual imageCodeYes:
Id = "ctl00_rightcontent_imageholder"
Border = "0"
Alt = "church in Adare"/>
Here, except for the SRC content and the ALT content, the others are fixed. We don't care about the ALT content, so we only need to focus on how to match the SRC content.
The regular expression provided here is: imgre = '. * s3.amazonaws.com/img?#.tnt.#/ (. ++ ?) \ ". * Ctl00_rightcontent_imageholder .*'
3. Use findall of the RE module to obtain the image name.
Result = Re. findall (imgre, response, re. s)
Print result
4. Save the image to your local device.
The urlretrieve method of the urllib module is used here.