Парсил сайт с выводом нужного текста.
def parse():
URL = 'https://www.battlemetrics.com/servers/valheim/10500658'
response = requests.get(URL)
soup = BeautifulSoup(response.content, 'html.parser')
items = soup.findAll('div', class_ = 'col-md-6 server-info')
comps = []
for item in items:
comps.append({
'title': item.find('dl', class_ = 'dl-horizontal')
})
for comp in comps:
print(comp['title'])
Вывод:
<dl class="dl-horizontal"><dt>Rank</dt><dd>#6286</dd><dt>Player count</dt><dd>3/20</dd><dt>Address</dt><dd><span title="185.189.255.206:2956">185.189.255.206<!-- -->:<!-- -->2956</span> <!-- -->(Game Port)<br/> <span title="185.189.255.206:2957">185.189.255.206<!-- -->:<!-- -->2957</span> <!-- -->(Query Port)</dd><dt>Status</dt><dd>online</dd><dt>Distance</dt><dd><span>928 km</span></dd><dt>Country</dt><dd><img alt="Russian Federation" height="11" src="https://cdn.battlemetrics.com/app/assets/ru.addac.gif" title="Russian Federation" width="16"/></dd><dt>Uptime</dt><dd><div>7 Days:<!-- --> <span style="color:hsl(93, 80%, 50%)">93%</span>, 30 Days:<!-- --> <span style="color:hsl(97, 80%, 50%)">97%</span><br/><a href="/servers/valheim/10500658/downtime">Downtime History</a></div></dd></dl>
Убрал не нужные теги с помощью:
get_text(strip=True)
Получил:
Rank#6286Player count4/20Address185.189.255.206:2956(Game Port)185.189.255.206:2957(Query Port)StatusonlineDistance928 kmCountryUptime7 Days:93%, 30 Days:97%Downtime History
Как мне вывести значение после
Player count
?