Ishan Verma
Ishan Verma

Reputation: 19

Error: pyMySQL is not working in spiders of scrapy

when I am importing pyMysql library in the scrapy project in python it is giving an error that no module found. I want to ask how can I import pyMysql library in python file of scrapy project. And when I am importing pyMySQL in simple python it is working properly.

in the spider , which was generated by command "genspider spider_name (url)" i used this code which is giving error .

enter code here

import scrapy
from amazon.items import AmazonItem
import pymysql


class AmazonProductSpider(scrapy.Spider):
    name = "AmazonDeals"
    allowed_domains = ["amazon.com"]

# Use working product URL below
start_urls = [
    "https://www.amazon.com/gp/product/B01IO0QWJA","https://www.amazon.in/Mi-Redmi-5-Gold-32GB/dp/B0756RF9KY"
]

def parse(self, response):
    items = AmazonItem()
    title = response.xpath('//h1[@id="title"]/span/text()').extract()
    sale_price = response.xpath('//span[contains(@id,"ourprice") or contains(@id,"saleprice")]/text()').extract()
    category = response.xpath('//a[@class="a-link-normal a-color-tertiary"]/text()').extract()
    availability = response.xpath('//div[@id="availability"]//text()').extract()
    items['product_name'] = ''.join(title).strip()
    items['product_sale_price'] = ''.join(sale_price).strip()
    items['product_category'] = ','.join(map(lambda x: x.strip(), category)).strip()
    items['product_availability'] = ''.join(availability).strip()
    yield items

Upvotes: 1

Views: 109

Answers (1)

Maxwell77
Maxwell77

Reputation: 939

Check that the PyMySQL module is installed:

python -c "import pymysql"

This command should returns nothing if everything is ok.

If it returns a ModuleNotFoundError, so install the module by using pip:

pip install PyMySQL

Upvotes: 1

Related Questions