-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# This is a combination of 2 commits.
# The first commit's message is: Add pyvideo spider # This is the 2nd commit message: add conference to spiders
- Loading branch information
1 parent
a0818b5
commit 840b73c
Showing
6 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import re | ||
|
||
from scrapy.contrib.spiders import CrawlSpider, Rule | ||
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor | ||
from scrapy.selector import Selector | ||
from pycon_speakers.items import Speaker | ||
|
||
|
||
class PyVideoSpider(CrawlSpider): | ||
name = 'pyvideo.org' | ||
allowed_domains = ['pyvideo.org'] | ||
start_urls = ['http://www.pyvideo.org/speaker/'] | ||
|
||
rules = ( | ||
# Extract links matching speakers | ||
Rule(SgmlLinkExtractor(allow=('/speaker/\d+/', )), callback='parse_speaker'), | ||
) | ||
|
||
def parse_speaker(self, response): | ||
sel = Selector(response) | ||
name = sel.xpath('//h1/text()').extract()[0].strip() | ||
for conf in sel.xpath('//div[@class="video-summary-data"]'): | ||
speaker = Speaker() | ||
speaker['name'] = name | ||
conf_text = conf.select('.//a/text()')[1].extract() | ||
speaker['conference'] = re.sub('\s20\d\d$','', conf_text) | ||
speaker['year'] = conf.re('20\d\d')[0] | ||
yield speaker |
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