Created
August 30, 2014 20:56
-
-
Save eliasdorneles/fd1644888c87c595c6ab to your computer and use it in GitHub Desktop.
Youtube Channel Video Lister
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scrapy | |
from scrapy.contrib.loader import ItemLoader | |
class YoutubeVideo(scrapy.Item): | |
link = scrapy.Field() | |
title = scrapy.Field() | |
views = scrapy.Field() | |
class YoutubeChannelLister(scrapy.Spider): | |
name = 'youtube-channel-lister' | |
youtube_channel = 'LongboardUK' | |
start_urls = ['https://www.youtube.com/user/%s/videos' % youtube_channel] | |
def parse(self, response): | |
for sel in response.css("ul#channels-browse-content-grid > li"): | |
loader = ItemLoader(YoutubeVideo(), selector=sel) | |
loader.add_xpath('link', './/h3/a/@href') | |
loader.add_xpath('title', './/h3/a/text()') | |
loader.add_xpath('views', ".//ul/li[1]/text()") | |
yield loader.load_item() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment