0
这是我第一次使用网络抓取的经验,我不知道我是否做得好。关键是我想同时抓取和抓取数据。如何同时抓取和抓取数据?
- 得到所有我会刮掉
- 商店他们到MongoDB的 链接
访问逐一刮其内容
# Crawling: get all links to be scrapped later on class LinkCrawler(Spider): name="link" allowed_domains = ["website.com"] start_urls = ["https://www.website.com/offres?start=%s" % start for start in xrange(0,10000,20)] def parse(self,response): # loop for all pages next_page = Selector(response).xpath('//li[@class="active"]/following-sibling::li[1]/a/@href').extract() if not not next_page: yield Request("https://"+next_page[0], callback = self.parse) # loop for all links in a single page links = Selector(response).xpath('//div[@class="row-fluid job-details pointer"]/div[@class="bloc-right"]/div[@class="row-fluid"]') for link in links: item = Link() url = response.urljoin(link.xpath('a/@href')[0].extract()) item['url'] = url items.append(item) for item in items: yield item # Scraping: get all the stored links on MongoDB and scrape them????
嘿,非常感谢。我在刮的网站是电子商务网站,人们出售物品,一旦出售,他们将其删除。因此,为了让我知道哪些产品销售得很快,我认为我必须保存链接,以便稍后检查是否删除或不删除。另外,如果有可能在mongodb上存储该链接之前刮取每个链接的内容,请告诉我该怎么做? –
如果指向个别产品的链接遵循一些常见模式,则最好使用['CrawlSpider'](https://doc.scrapy.org/en/latest/topics/spiders.html#crawlspider)和适当的规则。 –
是的个别产品,但有一个tuto在那里?我想访问每一个链接,并提取在那里暴露的数据... –