python - 运行2分钟后scrapy关闭
问题描述
我需要监控网页以找到可用的产品,并且我使用 scrapy 框架。如果我找到了产品,我会通知它。该网页在主页上有产品列表,其中包含有关它们的一些信息以及产品页面中的其他信息。
class Spider(scrapy.Spider):
name = 'productpage'
start_urls = ['https://www.productpage.com']
def parse(self, response):
for product in response.css('article'):
link = 'https://www. productpage' + product.css('a::attr(href)').get()
id = link.split('/')[-1]
title = product.css('a > span::attr(content)').get()
price = product.css('a > figure::text').get()
product = Product(self.name, id, title, price, image, size, link)
yield scrapy.Request('{}.json'.format(link), callback=self.parse_product, meta={'product': product})
yield scrapy.Request(url=response.url, callback=self.parse, dont_filter=True)
# The program pass this line and after some minutes it closes without error
def parse_product(self, response):
product = response.meta['product']
jsonresponse = json.loads(response.body_as_unicode())
product.image = jsonresponse['images'][0]['small_url']
for size in jsonresponse['available_sizes']:
product.size.append(u'{} | {}'.format(size['name'], size['id']))
send(product)
为什么程序要经过这条线?
yield scrapy.Request(url=response.url, callback=self.parse, dont_filter=True)
解决方案
推荐阅读
- networking - 无法从同一网络下的另一台设备(Android 手机)ping vm ip 地址
- excel - VBA Excel中的聚合函数
- typescript - Nestjs-从实体类创建自定义 json 响应
- excel-formula - Excel - 检查 2 个表格列表是否相同
- angular - 如何在角度 6 中的 Ng-select 下使用黄色突出显示选项
- java - 在 Java 中合并两个数组以保持顺序并使用第一个数组的唯一空白值
- c - 如何用-1初始化全局数组?
- cucumber-java - 出现错误错误:在 Eclipse 中执行我的功能文件时无法找到或加载主类 cucumber.api.cli.Main?
- html - 为嵌套的 LI 提供动态的 paddin-lfet 样式
- javascript - 如何防止对未安装组件的异步请求进行 React 状态更新?