2017-05-30 1 views
0

I Problem nach Paginierung dieser Website habe: http://gamesurf.tiscali.it/ps4/recensioni.htmlScrapy Python folgende Paginierung

Meine Spinne Teil des Codes:

for pag in response.css('li.square-nav'): 
    next = pag.css('li.square-nav > a > span::text').extract_first() 
    if next=='»': 
     next_page_url = pag.css('a::attr(href)').extract_first() 
     if next_page_url: 
      next_page_url = response.urljoin(next_page_url) 
      yield scrapy.Request(url=next_page_url, callback=self.parse) 

Wenn ich meine Spinne laufen auf Windows Terminal funktioniert es auf allen Seiten die website, aber wenn ich zu scrapinghub bereitstellen und von der taste im armaturenbrett laufen lasse, kratze Spinne nur die erste Seite der Web site. Zwischen Protokollmeldungen gibt es eine Warnung:

[py.warnings] /app/__main__.egg/reccy/spiders/reccygsall.py:21: 
UnicodeWarning: Unicode equal comparison failed to convert both arguments to 
Unicode - interpreting them as being unequal. 

Zeile 21, ist dies:

if next=='»': 

Ich habe überprüft Problem durch robot.txt verursacht wird, nicht. Wie kann ich das beheben? Dank

Hier wird die gesamte Spinne:

# -*- coding: utf-8 -*- 
import scrapy 


class QuotesSpider(scrapy.Spider): 
    name = 'reccygsall' 
    allowed_domains = ['gamesurf.tiscali.it'] 
    start_urls = ['http://gamesurf.tiscali.it/ps4/recensioni.html'] 

def parse(self, response): 
    for quote in response.css("div.boxn1"): 
     item = { 
      'title': quote.css('div.content.fulllayer > h3 > a::text').extract_first(), 
      'text': quote.css('div.content.fulllayer > h3 > a::attr(href)').extract_first(), 
     } 
     yield item 


    for pag in response.css('li.square-nav'): 
     next = pag.css('li.square-nav > a > span::text').extract_first() 
     if next=='»': 
      next_page_url = pag.css('a::attr(href)').extract_first() 
      if next_page_url: 
       next_page_url = response.urljoin(next_page_url) 
       yield scrapy.Request(url=next_page_url, callback=self.parse) 
+0

können Sie versuchen, ein Element mit einer XPath zu suchen: '// li [@ class =" square -nav "]/a [span]/@ href' – vold

+0

Versuchen Sie' # - * - coding: utf-8 - * - 'ganz am Anfang Ihrer Spider-Modul-Quelldatei hinzuzufügen, und verwenden Sie' if next == u ' »':' –

+0

nächste == u' »: ^ SyntaxError: ungültige Syntax –

Antwort

0

ich eine Lösung gefunden:

# -*- coding: utf-8 -*- 

import scrapy 


class QuotesSpider(scrapy.Spider): 
    name = 'reccygsall' 
    allowed_domains = ['gamesurf.tiscali.it'] 
    start_urls = ['http://gamesurf.tiscali.it/ps4/recensioni.html'] 

    contatore = 0 

    def parse(self, response): 
     for quote in response.css("div.boxn1"): 
      item = { 
       'title': quote.css('div.content.fulllayer > h3 > a::text').extract_first(), 
       'text': quote.css('div.content.fulllayer > h3 > a::attr(href)').extract_first(), 
      } 
      yield item 


      self.contatore = self.contatore + 1 
      a = 0 
      for pag in response.css('li.square-nav'): 
       next = pag.css('a::text').extract_first() 
       if next is None: 
        a = a+1; 
         if (self.contatore < 2) or (a > 1): 
          next_page_url = pag.css('a::attr(href)').extract_first() 

          if next_page_url: 
           next_page_url = response.urljoin(next_page_url) 
           yield scrapy.Request(url=next_page_url, callback=self.parse)