Python crawler, Douban top250 movie, pythontop250

Source: Internet
Author: User

Python crawler, Douban top250 movie, pythontop250
Python crawler, doubantop250 movie

import stringimport reimport urllib2class DouBanSpider(object) :    def __init__(self) :        self.page = 1        self.cur_url = "http://movie.douban.com/top250?start={page}&filter=&type="        self.datas = []        self._top_num = 1    def get_page(self, cur_page) :        url = self.cur_url.format(page = (cur_page - 1) * 25)        my_page = urllib2.urlopen(url).read().decode("utf-8")        return my_page    def find_title(self, my_page) :        temp_data = []        movie_items = re.findall(r'<span.*?class="title">(.*?)</span>', my_page, re.S)        for index, item in enumerate(movie_items) :            if item.find(" ") == -1 :                temp_data.append("Top" + str(self._top_num) + " " + item)                self._top_num += 1        self.datas.extend(temp_data)        def start_spider(self) :        while self.page <= 4 :            my_page = self.get_page(self.page)            self.find_title(my_page)            self.page += 1def main() :    my_spider = DouBanSpider()    my_spider.start_spider()    for item in my_spider.datas :        print itemmain()


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.