2017-04-27 129 views
0

这是我的代码。蜘蛛不抓取网址或不提取它们或类似的东西。如果我但在“启动网址”目标网址然后scrapy发现项目,但不会向前爬行,如果我但“启动网址”包含目标列表的url,那么结果为0。 :)我希望文本不混淆Scrapy只抓取一页

from scrapy.spiders import Spider 
from testing.items import TestingItem 
import scrapy 

class MySpider(scrapy.Spider): 
    name   = 'testing' 
    allowed_domains = ['http://somewebsite.com'] 
    start_urls  = ['http://somewebsite.com/listings.php'] 


    def parse(self, response): 
     for href in response.xpath('//h5/a/@href'): 
      full_url = response.urljoin(href.extract()) 
      yield scrapy.Request(full_url, callback=self.parse_item) 


    def parse_item(self, response): 
    titles = response.xpath('//*[@class="panel-content user-info"]').extract() 
    for title in titles: 
     item = TestingItem() 
     item["nimi"] = response.xpath('//*[@class="seller-info"]/h3/text()').extract() 

     yield item 
+1

尝试删除allowed_domains中的'http://' –

+1

尼斯,tanx伴侣:)。你知道我需要添加什么来分页到下一页吗? :) –

回答

1

您需要删除http://allowed_domains

要回答您的意见,对于pagination,您可以使用Rules,我会让你检查文档here。它可以让你轻松浏览分页。

小为例:

rules = (Rule(LinkExtractor(allow=(), restrict_xpaths=('xpath/to/nextpage/button',)), callback="parse", follow= True),) 

希望这有助于。

+1

不错!这是完美的人! Tanx很多! :) –