Skip to content

Commit

Permalink
Merge pull request #3 from aliciapj/03_capturando_ataques
Browse files Browse the repository at this point in the history
3 - Scrapeando ataques de pokexperto.net
  • Loading branch information
EdelBlau authored Dec 12, 2019
2 parents 17e52b0 + dbcc634 commit b9c0d9f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tutorial/tutorial/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ class PokemonItem(scrapy.Item):
weight = scrapy.Field()
evolution = scrapy.Field()
type = scrapy.Field()

class PokemonAttacksItem(scrapy.Item):
pokemon_id = scrapy.Field()
attack_list = scrapy.Field()

class AttackItem(scrapy.Item):
name = scrapy.Field()
type = scrapy.Field()
29 changes: 29 additions & 0 deletions tutorial/tutorial/spiders/attacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
import scrapy
from tutorial.items import PokemonAttacksItem, AttackItem


class AttackSpider(scrapy.Spider):
name = 'attacks'
allowed_domains = ['pokexperto.net']
start_urls = ['https://www.pokexperto.net/index2.php?seccion=nds/nationaldex/buscar']

def parse(self, response):
ult_pokemon = int(response.css('#listapokemon').re_first( r'([0-9]{3}) Pokémon' )) + 1
for i in range(1, ult_pokemon):
#for i in range(1, 5):
link = 'https://www.pokexperto.net/index2.php?seccion=nds/nationaldex/movimientos_pokemon&pk=' + str(i)
yield scrapy.Request(link, callback=self.parse_pokemon)

def parse_pokemon(self, response):
pokemon = PokemonAttacksItem()
pokemon['pokemon_id'] = response.css('td.left.pktitle span.amarillo::text').extract_first()
pokemon["attack_list"] = []
attacks_html = response.xpath('//tr[@class="check3 bazul"]')
for attack_html in attacks_html:
attack = AttackItem()
attack["type"] = attack_html.css('td img::attr(src)').re_first("tipos/(.*).png").capitalize()
attack["name"] = attack_html.css('a.nav6c::text').extract_first()
pokemon["attack_list"].append(attack)

yield pokemon

0 comments on commit b9c0d9f

Please sign in to comment.