Skip to content

Instantly share code, notes, and snippets.

@Jeffrey04
Created May 8, 2019 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jeffrey04/2b61774b6bd3510164b3415f0380b457 to your computer and use it in GitHub Desktop.
Save Jeffrey04/2b61774b6bd3510164b3415f0380b457 to your computer and use it in GitHub Desktop.
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