I have a spider, which has to find the «next» link —the one with the "»" inside— from this HTML:
<div id="content-center">
<div class="paginador">
<span class="current">01</span>
<a href="ml=0">02</a>
<a href="ml=0">03</a>
<a href="ml=0">04</a>
<a href="ml=0">»</a>
<a href="ml=0">Last</a>
</div>
</div>
I am trying with this spider
# -*- coding: utf-8 -*-
from scrapy.contrib.spiders import CrawlSpider
from scrapy.selector import Selector
from scrapy.http import Request
class YourCrawler(CrawlSpider):
name = "***"
start_urls = [
'http://www.***.com/10000000000177/',
]
allowed_domains = ["http://www.***.com/"]
def parse(self, response):
s = Selector(response)
page_list_urls = s.css('#content-center > div.listado_libros.gwe_libros > div > form > dl.dublincore > dd.title > a::attr(href)').extract()
for url in page_list_urls:
yield Request(response.urljoin(url), callback=self.parse_following_urls, dont_filter=True)
hxs = HtmlXPathSelector(response)
next_page = hxs.select(u"//*[@id='content-center']/div[@class='paginador']/a[text()='\u00bb']/@href").extract()
if next_page is not None:
next_page = response.urljoin(next_page)
yield Request(next_page, callback=self.parse)
def parse_following_urls(self, response):
for each_book in response.css('div#container'):
yield {
'title': each_book.css('div#content > div#primary > div > h1.title-book::text').extract(),
}
Does not recognize the link, any idea? Any Idea how to solve that?
Thanks!