2

I am trying to parse a webpage code for which is below. I am able to get the users using the xpath but i am unable to get their scores using xpath any ideas what i am doing wrong here ?

import requests from lxml import html internsHack = 'https://doselect.com/hackathon/inmobi-internshack/leaderboard' page = requests.get(internsHack) tree = html.fromstring(page.content) users = tree.xpath('//div[@class="md-list-item-text"]/h2/a/text()') score = tree.xpath('//div[@class="points-score"]/ng-pluralize/text()') 

1 Answer 1

2

HTML source snippet:

<div class="points-score"> <ng-pluralize count="200" when="{'0': '{} point', 'one': '{} point', 'other': '{} points'}"> </div> 

Get the count attribute values instead of text():

//div[@class="points-score"]/ng-pluralize/@count 

score variable would then have the following value:

['200', '198', '198', '197', '197', '197', '196', '195', '194', '194'] 
Sign up to request clarification or add additional context in comments.

3 Comments

Your answer is correct but curious to know how did you figure that count is a attribute as when i look for this in developer tools of chrome 200 points is a text item
@NickLoach what you see in the "Source" in browser developer tools is a rendered page by the browser which can seriously differ from the initial page. What you get with requests is the initial unrendered page - this is what you should inspect. Hope that helps.
Thanks for the explanation i examined request content now its illegible but you are correct about the count attribute

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.