Giter Site home page Giter Site logo

products_scraper's Introduction

Scrapy and Playwright Spider for Webpage Data Extraction

This project includes a Scrapy spider that uses Playwright to extract data from a webpage. The spider extracts the product names and the breadcrumb in a list format. It saves the results in a CSV file.

Installation

To use this project, you'll need to have Python 3, Scrapy, and Playwright installed. You can install Python 3 and pip using the following command sequence in Ubuntu:

sudo apt-get install software-properties-common
sudo apt-add-repository universe
sudo apt-get update
sudo apt install python3-pip

You can install virtualenv and create a new virtual environment for this project using the following commands:

sudo pip install virtualenv
mkdir ~/.storevirtualenvs
virtualenv -p python3 yourVenv

Replace yourVenv with the name you want to give to your virtual environment. To activate the virtual environment, run the following command:

source yourVenv/bin/activate

This will activate the virtual environment and any Python packages you install will be installed in the virtual environment, rather than globally on your system. You should see (yourVenv) at the beginning of your terminal prompt after running this command. To deactivate the virtual environment, simply run the deactivate command.

Requruiments

sudo pip install scrapy
sudo pip install playwright-scrapy
sudo playwright install

To install Playwright, follow the instructions for your operating system on the Playwright documentation page.

Usage

To run the spider, navigate to the third_part folder and activate your virtual environment. Then run the following command:

scrapy crawl products -o products.csv

This will start the spider and save the results in a CSV file named products.csv.

Output

The spider extracts the product names and breadcrumb in a list format. The breadcrumb is extracted as a list of strings, where each string represents a part of the breadcrumb. The desired format is:

["Home", "Drinks", "Cordials, Juices & Iced Teas", "Iced Teas"]

The product names are output using Scrapy.Items, which allows you to easily customize the output format.

Customization

You can customize the spider by modifying the following files:

  • myspider/spiders/myspider.py: This file contains the spider code. You can modify the Playwright code used to extract data from the page, as well as the output format.

  • myspider/items.py: This file defines the Scrapy.Item used to output the product names. You can modify the item fields to include additional product data.

Troubleshooting

If you encounter any issues while running the spider, try the following:

  • Make sure you have the latest version of Scrapy and Playwright installed.
  • Check the Playwright code used to extract data from the page to make sure it is correct.
  • If the spider is being blocked by the website, try setting the USER_AGENT in the spider settings to a different value.

products_scraper's People

Contributors

m-zemmouri avatar

Watchers

 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.