0

I want to scrape information from multiple urls. I use the following code but it doesn't work. May someone please points me to where I have gone wrong?

import scrapy

class spider1(scrapy.Spider):
    name = "spider1"
    domain = "http://www.amazon.com/dp/"
    ASIN = ['B01LA6171I', 'B00OUKHTLO','B00B7LUVZK']

    def start_request(self):
        for i in ASIN:
            yield scrapy.Request(url=domain+i,callback = self.parse)

    def parse(self, response):
       title =response.css("span#productTitle::text").extract_first().strip()
       ASIN_ext = response.xpath("//input[@name='ASIN']/@value").extract_first()
       data = {"ASIN":ASIN_ext,"title":title,}
       yield data
2
  • 1
    Please explain what error do you get? Commented Apr 21, 2017 at 6:34
  • The log didn't show any errors. But just says 0 pages are crawled. Commented Apr 21, 2017 at 6:52

1 Answer 1

6

You just need to add an 's' to the first function

def start_requests(self):

Subtle difference, but Scrapy looks for that specific function so it has to match perfectly.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! It works if i move the 'domain' and 'ASIN' variable into the start_requests() block. I am a newbie to python and scrapy. May I how to make these two variable accessible for all the functions defined in the class?
In your case, just prefix them with the class name when you reference them. The way you defined them is fine, but when you go to reference it would be spider1.domain and spider1.ASIN. Take a look here to learn more about the difference between class and object variables: ibiblio.org/g2swap/byteofpython/read/class-and-object-vars.html
@user45857, class attributes are accessible using the self object that is passed as first argument in class methods, e.g. def start_request(self): for i in self.ASIN:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.