[Script collection] extract tripntale Images

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.