Skip to content

Instantly share code, notes, and snippets.

@eliasdorneles
Created August 30, 2014 20:56
Show Gist options
  • Save eliasdorneles/fd1644888c87c595c6ab to your computer and use it in GitHub Desktop.
Save eliasdorneles/fd1644888c87c595c6ab to your computer and use it in GitHub Desktop.
Youtube Channel Video Lister
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