0

I use python 3 I use scrapy 2.4.1 I made a script to ask you to input some words and it will search about it my code The first URL work without problems and after that, it gives an error

from scrapy.crawler import CrawlerProcess
from scrapy.utils.project import get_project_settings
class Amazon_spiders(scrapy.Spider):
    name = "amazon"
    start = time.time( )
    search = []
    starting=[]
    parse_number=0
    custom_settings = {
        'DOWNLOD_DELAY': 1,
        'LOG_LEVEL': 'INFO',}
    #make folder
    try:
        os.mkdir('results folder')
    except FileExistsError:
        pass
    def __init__(self):
        self.outfile = open(f"results folder/ result date.csv", "w",newline="", encoding="utf-8")
        self.writer = csv.writer(self.outfile)
        self.writer.writerow(['Title', 'Price', 'url', 'Img', 'Ratings', 'Stars'])
        print("***" * 20, "opened")
    def start_requests(self):
        number = input('Enter the number of times to search \n')
        for n in range(int(number)):
            word = input("Enter one sentence to be searched  \n ")
            # Amazon_spiders.search.append(word)
            words = word.strip( )
            # replace space with +
            words = words.replace(' ', '+')
            url = f'https://www.amazon.com/s?k={words}&ref=nb_sb_noss'
            print(f'currant page {url}')
            yield Request(url=url, callback=self.parse)
process = CrawlerProcess(get_project_settings())

# 'amazon' is the name of one of the spiders of the project.
process.crawl('amazon')
process.start( )  # the script will block here until the crawling is finished

the error is

Traceback (most recent call last):
  File "C:/Users/ahmed/PycharmProjects/web scraping/Amazon/Amazon/spiders/amazon.py", line 109, in <module>
    process.start( )  # the script will block here until the crawling is finished
  File "C:\Users\ahmed\PycharmProjects\web scraping\venv\lib\site-packages\scrapy\crawler.py", line 327, in start
    reactor.run(installSignalHandlers=False)  # blocking call
  File "C:\Users\ahmed\PycharmProjects\web scraping\venv\lib\site-packages\twisted\internet\base.py", line 1282, in run
    self.startRunning(installSignalHandlers=installSignalHandlers)
  File "C:\Users\ahmed\PycharmProjects\web scraping\venv\lib\site-packages\twisted\internet\base.py", line 1262, in startRunning
    ReactorBase.startRunning(self)
  File "C:\Users\ahmed\PycharmProjects\web scraping\venv\lib\site-packages\twisted\internet\base.py", line 765, in startRunning
    raise error.ReactorNotRestartable()
twisted.internet.error.ReactorNotRestartable

Thanks for help

0 Answers0