我的Scrapy蜘蛛运行良好。 我需要做的是从解析方法内部进行API调用,并使用相同方法的相同方法使用响应结果。我该怎么做呢?唯一简单的想法是使用python请求库,但我不确定这是否适用于scrapy,而且在scrapinghub。有没有内置的解决方案? 这里是一个例子。Scrapy。如何将请求结果返回给调用方法?我可以在scrapy中使用python请求库吗?
def agency(self, response):
# inspect_response(response, self)
agents = response.xpath('//a[contains(@class,"agency-carousel__item")]')
Agencie_Name = response.xpath('//h1[@class = "agency-header__name"]/text()').extract_first()
Business_Adress = response.xpath('//div[@class = "agency-header__address"]//text()').extract()
Phone = response.xpath('//span[@class = "modal-item__text"]/text()').extract_first()
Website = response.xpath('//span[@class = "modal-item__text"][contains(text(),"Website")]/../@href').extract_first()
if Website:
pass
# 1 send request to hunter io and get pattern. Apply to entire team. Pass as meta
# do smth with this pattern in here using info from this page.
所以在这里我normaly提取scrapy响应的所有信息,如果填充网站可变我需要发送API调用来猎人io来获取电子邮件模式该域,并用它来生成相同的方法电子邮件。 希望能够让你感觉到。
请求库不是异步的,它会阻塞。我建议直接与反应堆工作(产生一个Deffered)或使用Celery发送电子邮件。 –
@AndrésPérez-Albela H什么会阻止?你的意思是它不适用于scrapy或将减慢整个事情?此外,我不需要发送电子邮件,我只需要使用此页面中的信息与新收到的模式一起工作。所以可能会发送另一个元数据请求到同一页面,这使得它效率不高。 –