View difference between Paste ID: VqZpXmEz and zhX5X4sa
SHOW: | | - or go back to the newest paste.
1
from bs4 import BeautifulSoup
2
3
import urllib2 #http://love-python.blogspot.nl/2008/02/get-html-source-of-url.html
4
5
url = 'http://services.runescape.com/m=itemdb_rs/top100.ws'
6
7
usock = urllib2.urlopen(url)
8
data = usock.read()
9
usock.close()
10
11
soup = BeautifulSoup(data).find_all('tbody')[0]
12
13
tr = soup.find_all('tr')
14
itnames = {}
15
itids = {}
16
for thistr in tr:
17
	td = thistr.find_all('td')
18
	a = td[0].find_all('a')[0]
19
	id = a['href'][a['href'].index('obj=')+4:]
20
	val = td[5].string
21
	if val[-1] == 'b':
22-
		val = val[:-1]
22+
		if val[-3:-1] == '.0':
23
			val = int(val[:-1])
24-
		val = float(val[:-1]) * 1000
24+
		else:
25
			val = float(val[:-1])
26
	else:
27
		val = int(float(val[:-1]) * 1000)
28
	itnames[a.string] = val
29
	itids[id] = val
30
31
print obj
32
33
# itids now contains all data in the format {"2":107.6,...}
34
# itnames now contains all data in the format {"Cannonball":107.6,...}