Python Crawl Beauty Pictures

Source: Internet
Author: User

Before I saw someone else write a Python script to crawl the picture, I wrote it before with regular, recently saw BeautifulSoup so take to practice practiced hand

# -*- coding:utf8 -*-from bs4 import beautifulsoupimport os, sys,  URLLIB2,TIME,RANDOM PATH = OS.GETCWD ()                       new_path =  Os.path.join (path,u ' sexy ') If not os.path.isdir (New_path):     os.mkdir (New_path)  def page_loop (page=1):    url =  ' http://sexy.faceks.com/tag/Beauty photography? page =%s '  % page    print url    content =  Urllib2.urlopen (URL)     soup = beautifulsoup (content)     my_ Girl = soup.findall (' A ', attrs={' class ': ' img '})     for girl in my_ girl:         #link  = girl.get (' src ')          girlink = girl.get (' href ')   #先获取首页每个美女图片的进入链接         print  Girlink        response = urllib2.urlopen (Girlink)          per_soup = beautifulsoup (response)          img_urls = per_soup.findall (' img ', attrs={' class ': None})           #print  img_urls        for img _url in img_urls:              Girlurl = img_url.get (' src ')               print girlurl  #获取单个美女的所有图片链接              content2 = urllib2.urlopen (Girlurl). Read ()              with&nbSp;open (U ' sexy ' + '/' +time.strftime ('%h%m%s ') +str (Random.randint (1000,9999)), ' WB ')  as code:                 code.write (Content2) Page_loop ()

As follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/73/E1/wKioL1YJDgDDT0EUAALvokfzBTI986.jpg "title=" QQ picture 20150928175232.jpg "alt=" Wkiol1yjdgddt0euaalvokfzbti986.jpg "/>

This article is from the "tireless learning ..." Blog, be sure to keep this source http://jonyisme.blog.51cto.com/3690784/1698895

Python Crawl Beauty Pictures

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.