class PythonEventsSpider(scrapy.Spider):
name = 'goodspider'
start_urls=['https://www.amazon.com/s?me=A33IZBYF4IBZTP&marketplaceID=ATVPDKIKX0DER']
details=[]
def parse(self, response):
base_url="https://www.amazon.com"
#code here
next_page=base_url+response.xpath('//li[@class="a-last"]/a/@href').extract_first()
print(next_page)
if "page=3" not in next_page:
yield scrapy.Request(url=next_page,callback=self.parse)
else:
#raise CloseSpider('bandwidth_exceeded')
#exit("Done")
Hello,i would like to stop the program when it reaches page 3 the url will be as follows https://www.amazon.com/s?i=merchant-items&me=A33IZBYF4IBZTP&page=3&marketplaceID=ATVPDKIKX0DER&qid=1555628764&ref=sr_pg_3
I Have tried some of the answers online but it didn't work the program kept run. what i want is to add a line or a function in the else
statement to end scrapy runspider test.py -o test.csv