python - twisted.internet.error.ReactorNotRestartable 多个 URL
问题描述
我使用python 3 我使用scrapy 2.4.1 我制作了一个脚本让你输入一些单词,它会搜索我的代码第一个URL工作没有问题,然后它给出了一个错误
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
错误是
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
感谢帮助
解决方案
推荐阅读
- c++ - 了解异步/重叠 IO
- javascript - 无法从 ejs 文件中检索字符串
- python - 无法在 Jupyter 中导入 AllenNLP
- odoo - 当用户在 Odoo 10 中创建销售订单时如何禁用“您已被分配”电子邮件
- javascript - 使用 XML 和 XPath 构建简单的数据库搜索网站
- authentication - Nuxt.js auth 如何使用刷新令牌?
- forms - 将 Google 表单复制到另一个包含完整数据的帐户
- angular - 如何在 sweetalert 中验证多个输入
- firebase - 为什么在电话认证期间没有短信代码 Flutter Firebase
- python - spyder 中没有名为“sklearn.model_selection”的模块