que tienen una dirección URL de la forma:Scrapy - análisis de los artículos que están paginados
example.com/foo/bar/page_1.html
Hay un total de 53 páginas, cada una de ellas tiene ~ 20 filas.
Básicamente quiero obtener todas las filas de todas las páginas, es decir ~ 53 * 20 elementos.
código He trabajando en mi método de análisis, que analiza una sola página, y también va una página más profundo por artículo, para obtener más información sobre el artículo:
def parse(self, response):
hxs = HtmlXPathSelector(response)
restaurants = hxs.select('//*[@id="contenido-resbus"]/table/tr[position()>1]')
for rest in restaurants:
item = DegustaItem()
item['name'] = rest.select('td[2]/a/b/text()').extract()[0]
# some items don't have category associated with them
try:
item['category'] = rest.select('td[3]/a/text()').extract()[0]
except:
item['category'] = ''
item['urbanization'] = rest.select('td[4]/a/text()').extract()[0]
# get profile url
rel_url = rest.select('td[2]/a/@href').extract()[0]
# join with base url since profile url is relative
base_url = get_base_url(response)
follow = urljoin_rfc(base_url,rel_url)
request = Request(follow, callback = parse_profile)
request.meta['item'] = item
return request
def parse_profile(self, response):
item = response.meta['item']
# item['address'] = figure out xpath
return item
La pregunta es, ¿cómo puedo rastrear cada página?
example.com/foo/bar/page_1.html
example.com/foo/bar/page_2.html
example.com/foo/bar/page_3.html
...
...
...
example.com/foo/bar/page_53.html
start_urls idea is great. muchas gracias – AlexBrand
Excelente respuesta. Muchas gracias por esto. El LinkExtractor en el sitio de scrapy no funcionó para mí. Esto hizo. –
cómo comprobar si no se encuentra la página. solo tiene 53 páginas. pero si llamo 'xrange (1,60)'. – user1586957