Created
October 11, 2016 20:23
-
-
Save DmitriyLyalyuev/23ee076ee38c565855f8c22f55ad0f66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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