GithubHelp home page GithubHelp logo

kenlock / scraping-jumia-ecommerce Goto Github PK

View Code? Open in Web Editor NEW

This project forked from krizten/scraping-jumia-ecommerce

0.0 1.0 0.0 119 KB

Using the Scrapy framework to scrape data consisting of name, brand, rating, price, product URL and image URLs of laptops on Jumia e-commerce (https://www.jumia.com.ng) into XLSX, SQL and MongoDB.

Python 100.00%

scraping-jumia-ecommerce's Introduction

Scraping-Jumia-Ecommerce


This repository provides a concise explanation on how to export scraped data to MongoDB, MySQL and XLSX using Scrapy. For this example, Scrapy 1.5 was used and you can download it using: $pip install scrapy

Also, you can find the documentation here.

On completing the installation, run $pip install -r requirements.txt to install the modules in the requirements.txt file.

Scrapy Project Folder Tree Scrapy Project Folder Tree

1. Configuring Scrapy to write data to MongoDB


Navigate to settings.py under the Project directory and edit the Pipeline section as follow:

# Configure item pipelines
# See https://doc.scrapy.org/en/latest/topics/item-pipeline.html
ITEM_PIPELINES = {
   'Jumia.pipelines.MongoDBPipeline': 300,
}

MONGODB_HOST = 'localhost'   # modify host and port if running hosting is cloud-based.
MONGODB_PORT = 27017
MONGODB_DB = 'laptops_db'
MONGODB_COLLECTION = 'laptops_collection'

Once that is done, the next objective is to define the pipeline in pipelines.py

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html

from pymongo import MongoClient
from scrapy.conf import settings


class MongoDBPipeline(object):
    def __init__(self):
        connection = MongoClient(settings['MONGODB_HOST'],
                                 settings['MONGODB_PORT'])
        db = connection[settings['MONGODB_DB']]
        self.collection = db[settings['MONGODB_COLLECTION']]

    def process_item(self, item, spider):
        self.collection.insert(dict(item))
        return item

And finally, ensure MongoDB is running either on localhost or on the cloud then run $scrapy crawl spider_name

Result: Exported to MongoDB

scraping-jumia-ecommerce's People

Contributors

krizten avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.