Skip to content

Instantly share code, notes, and snippets.

@DmitriyLyalyuev
Created October 11, 2016 20:23
Show Gist options
  • Save DmitriyLyalyuev/23ee076ee38c565855f8c22f55ad0f66 to your computer and use it in GitHub Desktop.
Save DmitriyLyalyuev/23ee076ee38c565855f8c22f55ad0f66 to your computer and use it in GitHub Desktop.
def get_ratings():
result = {}
url = 'https://readrate.com/rus/users/%s/books' % (os.environ.get('USERID'))
html = lxml.html.fromstring(urllib2.urlopen(url).read())
books = html.xpath('//div[@class="book item"]')
for book in books:
title = book.xpath('div/div[2]/div/div/a')[0].text
rating = len(book.xpath('div[@class="wrapper clearfix"]/div[@class="cover"]/div[@class="picture"]/div[@class="content"]/div[@class="user-rating-stars"]/ul/li[contains(@class, "active")]'))
result.update({title: rating})
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment