-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.py
39 lines (27 loc) · 842 Bytes
/
data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from lxml import html
from funcs import *
import requests
import pandas as pd
page = requests.get('http://pokemondb.net/pokedex/all')
tree = html.fromstring(page.content)
tr_elements = tree.xpath('//tr')
stats = ["Name", "Type", "Total", "HP", "Attack", "Defence", "Sp.Atk", "Sp.Def", "Speed"]
head = ["000", stats]
pok = [head]
for c in range(1, len(tr_elements)):
temp = []
temp_t = []
for x in tr_elements[c].iterchildren():
tt = x.text_content().lstrip(' ')
temp.append(tt)
temp_t.append(temp[0])
temp.pop(0)
temp_t.append(temp)
pok.append(temp_t)
for a in range(1, len(pok)):
pok[a][1][0] = format_name(pok[a][1][0])
pok[a][1][1] = format_type(pok[a][1][1])
print pok
Dict = {title: column for (title, column) in pok}
df = pd.DataFrame(Dict)
df.to_json('PokemonData.json')