Answer the question
In order to leave comments, you need to log in
Which one to get the last element?
How to get the last Rating from this table, namely 12448 (it will always be different)
Tried using xpath
tree = html.fromstring(pars.content)
stata = tree.xpath('//*[@id="bg"]/div[3]/div/div/div/div/div/div/div/div/div/table/tbody/tr[32]/td[3]')
print(stata)
<table class="cntr wa mlra">
<tbody><tr>
<td class="p5">Место</td>
<td class="p5">Имя</td>
<td class="p5">Рейтинг</td>
</tr>
<tr>
<td class="yell">1</td>
<td class="">
<a href="/view_profile?player_id=4310386" class="lwhite">Sherman</a>
</td>
<td class="yell">67131</td>
</tr><tr>
</tr><tr>
<td class="yell">2</td>
<td class="">
<a href="/view_profile?player_id=2952751" class="lwhite">Astаrta</a>
</td>
<td class="yell">65960</td>
</tr><tr>
</tr><tr>
<td class="yell">3</td>
<td class="">
<a href="/view_profile?player_id=8233419" class="lwhite">killernik</a>
</td>
<td class="yell">65958</td>
</tr><tr>
</tr><tr>
<td class="yell">4</td>
<td class="">
<a href="/view_profile?player_id=7216037" class="lwhite">Мaркизa</a>
</td>
<td class="yell">65423</td>
</tr><tr>
</tr><tr>
<td class="yell">5</td>
<td class="">
<a href="/view_profile?player_id=3334852" class="lwhite">КрошкаРy</a>
</td>
<td class="yell">64779</td>
</tr><tr>
</tr><tr>
<td class="yell">6</td>
<td class="">
<a href="/view_profile?player_id=2471064" class="lwhite">Лисёнок Ди</a>
</td>
<td class="yell">64192</td>
</tr><tr>
</tr><tr>
<td class="yell">7</td>
<td class="">
<a href="/view_profile?player_id=7940254" class="lwhite">Whitе Eagle</a>
</td>
<td class="yell">64191</td>
</tr><tr>
</tr><tr>
<td class="yell">8</td>
<td class="">
<a href="/view_profile?player_id=2741792" class="lwhite">Юля лучшая</a>
</td>
<td class="yell">64063</td>
</tr><tr>
</tr><tr>
<td class="yell">9</td>
<td class="">
<a href="/view_profile?player_id=5043654" class="lwhite">НЕЗЕРИЛ</a>
</td>
<td class="yell">63876</td>
</tr><tr>
</tr><tr>
<td class="yell">10</td>
<td class="">
<a href="/view_profile?player_id=5773233" class="lwhite">ЗагорскиЙ</a>
</td>
<td class="yell">63739</td>
</tr><tr>
</tr><tr>
<td class="yell">11</td>
<td class="">
<a href="/view_profile?player_id=1963843" class="lwhite">Баргузин</a>
</td>
<td class="yell">63393</td>
</tr><tr>
</tr><tr>
<td class="yell">12</td>
<td class="">
<a href="/view_profile?player_id=3571824" class="lwhite">СПАРТАНЕЦ АА</a>
</td>
<td class="yell">63309</td>
</tr><tr>
</tr><tr>
<td class="yell">13</td>
<td class="">
<a href="/view_profile?player_id=3121447" class="lwhite">Кучум</a>
</td>
<td class="yell">63266</td>
</tr><tr>
</tr><tr>
<td class="yell">14</td>
<td class="">
<a href="/view_profile?player_id=4585462" class="lwhite">verdikt</a>
</td>
<td class="yell">63102</td>
</tr><tr>
</tr><tr>
<td class="yell">15</td>
<td class="">
<a href="/view_profile?player_id=949862" class="lwhite">Голд Лис</a>
</td>
<td class="yell">63022</td>
</tr><tr>
</tr><tr>
<td class="yell">6182</td>
<td class="">
<a href="/view_profile?player_id=882276" class="lyell">Allabama</a>
</td>
<td class="yell">
12448 </td>
</tr><tr>
</tr></tbody></table>
Answer the question
In order to leave comments, you need to log in
If only the last rating is needed, is it worth bothering with building and searching in the DOM model. The search is slow, when processing large pages, the memory eats up unmeasured.
It's easier to find a hand-to-hand rating
import requests
. . .
content = requests.get('адрес чего-то')
texthtm = content.text
substr = '<td class="yell">'
posb = texthtm.rfind(substr) + len(substr)
pose = texthtm.find('</', posb)
rating = int(texthtm[posb : pose])
print(rating)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question