2016-07-14 11 views
1

Ich versuche, URLs für Einträge in Parse_start_url-Methode, die eine Anfrage mit einem Rückruf an Parse_link-Methode ergibt, aber der Rückruf scheint nicht zu funktionieren. Was mache ich falsch?Benutzerdefinierte Analyse Callback-Anfrage funktioniert nicht in Scrapy

Code:

from scrapy import Request 
from scrapy.selector import Selector 
from scrapy.linkextractors import LinkExtractor 
from scrapy.spiders import Rule, CrawlSpider 
from property.items import PropertyItem 
import sys 

reload(sys) 
sys.setdefaultencoding('utf8') #To prevent UnicodeDecodeError, UnicodeEncodeError. 

class VivastreetSpider(CrawlSpider): 
    name = 'viva' 
    allowed_domains = ['chennai.vivastreet.co.in'] 
    start_urls = ['http://chennai.vivastreet.co.in/rent+chennai/'] 
    rules = [ 
     Rule(LinkExtractor(restrict_xpaths = '//*[text()[contains(., "Next")]]'), callback = 'parse_start_url', follow = True) 
     ] 

    def parse_start_url(self, response): 
     urls = Selector(response).xpath('//a[contains(@id, "vs-detail-link")]/@href').extract() 

     for url in urls: 
      print('test ' + url) 
      yield Request(url = url, callback = self.parse_link) 

    def parse_link(self, response): 
     #item = PropertyItem() 
     print('parseitemcalled') 
     a = Selector(response).xpath('//*h1[@class = "kiwii-font-xlarge kiwii-margin-none"').extract() 
     print('test ' + str(a)) 

Antwort

0

Sie benötigen allowed_domains anpassen die extrahierten URLs zu ermöglichen, werden gefolgt:

allowed_domains = ['vivastreet.co.in'] 

Dann Sie in ungültiger Ausdruck Fehler erhalten werden, ist dies, weil //*h1[@class = "kiwii-font-xlarge kiwii-margin-none" ist ungültig und muss repariert werden.

Verwandte Themen