View difference between Paste ID: FbCjTpys and y0RRvVrQ
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(BeautifulSoup(data).find_all('tbody'))
11+
soup = BeautifulSoup(BeautifulSoup(data).find_all('tbody')[0])
12
13-
tr = BeautifulSoup(soup.find_all("tr"))
13+
tr = soup.find_all("tr")
14
obj = {}
15
for thistr in tr:
16-
	td = BeautifulSoup(thistr).find_all('td')
16+
	bstr = BeautifulSoup(thistr)
17-
	obj[thistr['data-item-id']] = BeautifulSoup(td[5]).string
17+
	td = bstr.find_all('td')
18
	obj[bstr['data-item-id']] = BeautifulSoup(td[5]).string
19
20
#obj now contains all data in the format {"2":"107.6m",...}