Created
May 8, 2019 05:25
-
-
Save Jeffrey04/2b61774b6bd3510164b3415f0380b457 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import json | |
import requests | |
from lxml.html import fromstring | |
def pokemon_get_type(tree): | |
result = [] | |
for _type in tree.cssselect('.itype'): | |
result.append(_type.text_content()) | |
return result | |
base_url = 'https://pokemondb.net' | |
response = requests.get('{}/pokedex/national'.format(base_url)) | |
tree = fromstring(response.text) | |
for monster in tree.cssselect('.infocard-list .infocard'): | |
response = requests.get(''.join([base_url, monster.cssselect('.ent-name')[0].get('href')])) | |
tree = fromstring(response.text) | |
print(json.dumps({ | |
"name": monster.cssselect('.ent-name')[0].text_content(), | |
"id": tree.cssselect('.vitals-table tbody td')[0].text_content(), | |
"type": pokemon_get_type(monster), | |
"species": tree.cssselect('.vitals-table tbody td')[2].text_content(), | |
"height": tree.cssselect('.vitals-table tbody td')[3].text_content(), | |
"weight": tree.cssselect('.vitals-table tbody td')[4].text_content(), | |
})) | |
time.sleep(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment