Created
December 16, 2015 12:58
-
-
Save masnun/e85b38a00a74737bb3eb to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
import scrapy | |
class MySpider(scrapy.Spider): | |
name = "myspider" | |
def start_requests(self): | |
return [ | |
scrapy.Request('http://masnun.com') | |
] | |
def parse(self, response): | |
anchors = response.css('a::text').extract() | |
for a in anchors: | |
yield {'text': a} | |
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
rom pymongo import MongoClient | |
from scrapy.conf import settings | |
import logging | |
class MongoPipeline(object): | |
def __init__(self): | |
connection = MongoClient(settings['MONGODB_HOST'], settings['MONGODB_PORT']) | |
self.db = connection[settings['MONGODB_DATABASE']] | |
def process_item(self, item, spider): | |
collection = self.db[type(item).__name__.lower()] | |
logging.info(collection.insert(dict(item))) | |
return item |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment