lxml xpath无法正常工作

时间:2015-12-02 01:57:46

标签: python html xpath web-scraping lxml

我正在尝试解析下面的网页代码。 我能够让用户使用xpath,但是我无法使用xpath得到他们的分数我在这里做错了什么?

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 个答案:

答案 0 :(得分:2)

HTML源代码段:

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

获取count属性值而不是text()

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

score变量将具有以下值:

['200', '198', '198', '197', '197', '197', '196', '195', '194', '194']