View difference between Paste ID: iDUjUJte and TDYZ92ED
SHOW: | | - or go back to the newest paste.
1-
from bs4 import BeautifulSoup
1+
from lxml import parse
2
3-
import urllib2 #http://love-python.blogspot.nl/2008/02/get-html-source-of-url.html
3+
doc = parse('http://services.runescape.com/m=itemdb_rs/top100.ws').getroot()
4
5-
url = 'http://services.runescape.com/m=itemdb_rs/top100.ws'
5+
6
cells = doc.cssselect('tbody tr[data-item-id] td:last-child')
7-
usock = urllib2.urlopen(url)
7+
for td in cells:
8-
data = usock.read()
8+
	obj[td.get('data-item-id')] = td.text_content()
9-
usock.close()
9+
10
print obj
11-
soup = BeautifulSoup(data)
11+
12
#obj now contains all data in the format {"2":"107.6m",...}