zol 벽지 사이트 의 모든 벽지

# _*_ coding:utf-8 _*_
"""  zol          """

import time
from bs4 import BeautifulSoup
import requests
class ZolSpider(object):
    def __init__(self, url=''):
        self.url = url
        self.base_url = 'http://desk.zol.com.cn'

    def get_html(self):
        """     html    beautifulsoup  """
        url = self.url
        html = requests.get(url)
        soup_html = BeautifulSoup(html.content, 'html.parser')
        return soup_html

    def spider(self):
        """      """
        CategorySpider(self.base_url).category_spider()
#   
class CategorySpider(ZolSpider):
    def get_category_url(self):
        """       """
        soup_html = self.get_html()
        category_url = []
        category = soup_html.find('dl', class_='filter-item first clearfix')
        for child in category.find_all('a'):
            category_url.append(self.base_url + child['href'])
        return category_url

    def category_spider(self):
        """        """
        for url in self.get_category_url():
            print('Current_Category:' + url.split('.cn')[-1])
            PhotoListSpider(url).list_spider()
            time.sleep(10)
#     
class PhotoListSpider(ZolSpider):
    def get_photo_list_url(self):
        """        """
        soup_html = self.get_html()
        photo_list_url = []
        photo_list = soup_html.find_all('li', class_='photo-list-padding')
        for child in photo_list:
            photo_list_url.append(self.base_url + child.a['href'])
        return photo_list_url

    def get_next_page_url(self):
        """       """
        soup_html = self.get_html()
        next_page_tag = soup_html.find('a', id='pageNext')
        next_page_url = self.base_url + next_page_tag['href']
        return next_page_url

    def list_spider(self):
        """        """
        print(u'Current_List:' + self.url.split('.cn')[-1])
        next_page = self.get_next_page_url()
        self.photo_spider()
        if next_page:
            PhotoListSpider(next_page).list_spider()
            time.sleep(5)

    def photo_spider(self):
        """      """
        for url in self.get_photo_list_url():
            print('Current_Set:' + url)
            PhotoSpider(url).photo_spider()
            time.sleep(2)
#     
class PhotoSpider(ZolSpider):
    def get_photo_url(self):
        """      """
        soup_html = self.get_html()
        img_tag = soup_html.find('img', id='bigImg')
        img_url = img_tag['src']
        return img_url

    def get_next_page_url(self):
        """       """
        soup_html = self.get_html()
        next_page_tag = soup_html.find('div', id='photo-next')
        _next_page_url = self.base_url + next_page_tag.a['href']
        return _next_page_url

    def photo_spider(self):
        """        """
        print('Photo_Url: ' + self.get_photo_url())
        next_page = self.get_next_page_url()
        if 'javascript' not in next_page:
            PhotoSpider(next_page).photo_spider()
if __name__ == '__main__':
    ZolSpider().spider()

좋은 웹페이지 즐겨찾기