# -*- coding: utf-8 -*-
import scrapy
from ironman_spider.items import RaceNameItem

class RaceNameSpider(scrapy.Spider):
    name = 'race_name_spider'
    allowed_domains = ['ironman.com']
    start_urls = ["http://eu.ironman.com/triathlon/events/emea/sprints/company-triathlon/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/multisport/multisport-westfriesland/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/austria/athletes/side-events/iron-girl/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/itu/itu-world-triathlon-hamburg-sprint-distance/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/austria/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/itu/itu-world-triathlon-hamburg-olympic-distance/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/jonkoping/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/5150/davao-philippines/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/muskoka/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/ecuador/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/muncie/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/astana/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/uk/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/vitoria-gasteiz/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/5150/5150-zurich/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/switzerland/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/santa-rosa/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/canada/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman/lake-placid/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/hamburg/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/ohio/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman/canada/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/multisport/multisport-maastricht/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/tallinn/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/boulder/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/alagoas/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/calgary/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/iron-girl/pleasant-prairie/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/gdynia/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/philippines/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/iron-girl/grimsby/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/sprints/kalmar-mini-tri/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/sprints/kmd-4184-denmark/copenhagen/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/kalmar/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/5150/5150-bela-bela/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/copenhagen/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman/mont-tremblant/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/vichy/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/vichy/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/dun-laoghaire/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/bintan/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/maine/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/vichy/athletes/iron-girl/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/traverse-city/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/zell-am-see-kaprun/athletes/side-events/iron-girl/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/zell-am-see-kaprun/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/nice/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/70.3-world-championship/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/santa-cruz/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/lake-placid/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman/wisconsin/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/sunshine-coast/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/sprints/kmd-4184-denmark/aarhus/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/5150/5150-aarhus/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/atlantic-city/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/xian/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/wales/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/superfrog/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/emilia-romagna/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/5150/5150-cervia-emilia-romagna/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/weymouth/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/emilia-romagna/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman/korea/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/slovenianistria/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/rio-de-janeiro/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman/maryland/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman/chattanooga/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/short-course/5i50-buenos-aires/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman/taiwan/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/cascais/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/augusta/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/cozumel/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/lanzarote/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/barcelona/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/barcelona/side-events/iron-girl/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman/world-championship/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman/louisville/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/north-carolina/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/coquimbo/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/5150/5150-ekurhuleni/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/goa/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/arizona/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/shanghai/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/running/marathon-de-bordeaux/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman/malaysia/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/langkawi/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/5150/subic-bay-philippines/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/running/chengdu-marathon/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/marrakech/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/waco/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/5150/5150-muscat/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman/florida/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/turkey/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/buenos-aires/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/los-cabos/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/multisports/noosa/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/running/across-the-bay-10k/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/sao-paulo/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/xiamen/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman/arizona/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/western-sydney/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/5150/5150-nelson-mandela-bay/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman/cozumel/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/running/singapore-marathon/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/bahrain/register/iron-girl/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman/western-australia/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman/mar-del-plata/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/western-australia/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/cartagena/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/taupo/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/bahrain/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/indian-wells-la-quinta/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/pucon/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/south-africa/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/dubai/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/oman/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/bangsaen/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/geelong/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/bariloche/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/running/santa-cruz-half-marathon/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/new-zealand/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman/new-zealand/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/itu/itu-world-triathlon-abu-dhabi/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/multisports/the-motatapu/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/san-juan/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/multisports/mooloolaba/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/taiwan/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/campeche/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/short-course/superseal/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/sprints/seal-sprint/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/davao/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/5150/liv-iron-girl/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/uruguay/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/south-africa/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/oceanside/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/texas/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/qujing/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/costa-navarino/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/liuzhou/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/peru/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/florida/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman/texas/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/marbella/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/florianopolis/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/5150/cebu-philippines/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman/st.-george/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/virginia/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/port-macquarie/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/monterrey/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman/australia/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/busselton/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/mallorca/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/5150/5150-croatia/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/vietnam/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/gulf-coast/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/pays-d-aix/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/chattanooga/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/barcelona/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/sprints/kmd-4184-denmark/odense/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/multisports/swim-noosa/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/hawaii/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman/tulsa/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/connecticut/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/victoria/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/kraichgau/side-events/iron-girl/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman/brazil/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/sprints/kmd-4184-denmark/aalborg/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/durban/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/subic-bay-philippines/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/switzerland/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/wisconsin/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/5150/5150-kraichgau/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/cairns/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/kraichgau/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/eagleman/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman/cairns/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/fortaleza/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/staffordshire/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman/subic-bay-philippines/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/japan/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/otepaa/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/luxembourg/side-events/iron-girl/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/france/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/5150/5150-warsaw/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/short-course/mont-tremblant/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/cork/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/goseong-korea/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/sprints/kmd-4184-denmark/elsinore/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/mont-tremblant/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/luxembourg/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/des-moines/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/costa-rica/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/elsinore/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/short-course/5150-costa-rica/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/frankfurt/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/steelhead/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/haugesund/athletes/irongirl/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/coeur-d-alene/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/lubbock/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/finland/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/haugesund/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/haugesund/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/france/athletes/iron-girl/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman-70.3/les-sables-dolonne/results.aspx",
                "http://eu.ironman.com/triathlon/events/emea/ironman/switzerland-thun/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman/santa-rosa/results.aspx",
                "http://eu.ironman.com/triathlon/events/asiapac/ironman-70.3/70.3-world-championship-taupo/results.aspx",
                "http://eu.ironman.com/triathlon/events/americas/ironman-70.3/st.-george/results.aspx", ]

    def parse(self, response):
        if response.status == 200:
            name = response.xpath('//form[@id="filterResultsForm"]/input[@name="race"]/@value').get()
            if name is not None:
                item = RaceNameItem()
                item['name'] = name
                item['url'] = response.url
                yield item
        else:
            print("响应失败："+response.url)
