@@ -0,0 +1,1848 @@
+from lxml import html%0Aimport requests%0Aimport time%0A%0Aclass AppCrawler:%0A%0A    def __init__(self, starting_url, depth):%0A        self.starting_url = starting_url%0A        self.depth = depth%0A        self.current_depth = 0%0A        self.depth_links = %5B%5D%0A        self.apps = %5B%5D%0A%0A    def crawl(self):%0A        app = self.get_app_from_link(self.starting_url)%0A        self.apps.append(app)%0A        self.depth_links.append(app.links)%0A%0A        while self.current_depth %3C self.depth:%0A            current_links = %5B%5D%0A            for link in self.depth_links%5Bself.current_depth%5D:%0A                current_app = self.get_app_from_link(link)%0A                current_links.extend(current_app.links)%0A                self.apps.append(current_app)%0A                time.sleep(5)%0A            self.current_depth += 1%0A            self.depth_links.append(current_links)%0A%0A%0A    def get_app_from_link(self, link):%0A        start_page = requests.get(link)%0A        tree = html.fromstring(start_page.text)%0A%0A        name = tree.xpath('//h1%5B@itemprop=%22name%22%5D/text()')%5B0%5D%0A        developer = tree.xpath('//div%5B@class=%22left%22%5D/h2/text()')%5B0%5D%0A        price = tree.xpath('//div%5B@itemprop=%22price%22%5D/text()')%5B0%5D%0A        links = tree.xpath('//div%5B@class=%22center-stack%22%5D//*/a%5B@class=%22name%22%5D/@href')%0A%0A        app = App(name, developer, price, links)%0A%0A        return app%0A%0A%0Aclass App:%0A%0A    def __init__(self, name, developer, price, links):%0A        self.name = name%0A        self.developer = developer%0A        self.price = price%0A        self.links = links%0A%0A    def __str__(self):%0A        return (%22Name: %22 + self.name.encode('UTF-8') + %0A        %22%5Cr%5CnDeveloper: %22 + self.developer.encode('UTF-8') + %0A        %22%5Cr%5CnPrice: %22 + self.price.encode('UTF-8') + %22%5Cr%5Cn%22)%0A%0A%0Acrawler = AppCrawler('https://itunes.apple.com/us/app/candy-crush-saga/id553834731', 2)%0Acrawler.crawl()%0A%0Afor app in crawler.apps:%0A    print app

add source file