S
S
saints.2020-01-21 22:35:20
PHP
saints., 2020-01-21 22:35:20

How to pull out the desired text in phpQuery when parsing if its class matches another text?

Hello, I encountered such a problem when parsing in phpQuery ,
on the site from which I extract data from the element I need, the class matches the other one
and at the output I get, in addition to what I need, another text and remove it using remove();
impossible, it will also remove what I need since they have one class for two:

serverPage-contentExtra serverPage-contentExtra-Ellipsis tooltipstered

Parser code:
parser
$infoData = pq( '.serverPage-contentExtra-Ellipsis' );
  foreach ( $infoData as $Data )
  {

    $Data = pq( $Data );
    //$Data->find( 'span' )->remove();

    xprint( $Data->text() );

  }

parser result:
5e274d91c9cd3267518672.png
The last of the presented "List of cards" I know how to remove
$Data->find( 'span' )->remove();

but here is the second one
7 days - 99.72%, 14 days - 99.72%, 28 days - 99.72%

I can’t remove it in this way,
I need to parse this text:
2 days 5 hours 56 minutes

without capital two of the presented
code from the site:
2 days 8 hours 37 minutes
<div class="serverPage-contentBox serverPage-contentBox-InlineExtra">
  <div class="serverPage-contentLabel">
    <h3 class="serverPage-contentLabelText serverPage-contentLabelText-Icon serverPage-contentLabelText-IconStatus"> Статус сервера </h3>
  </div>
  <div class="serverPage-status2 "> ONLINE </div>
  <div class="serverPage-contentExtra serverPage-contentExtra-Ellipsis tooltipstered" data-tooltip="Длительность непрерывного нахождения сервера в данном статусе" data-tooltipimage="/img/icon/clock_white.svg"> 2 дня 5 часов 56 минут </div>
</div>

7 days - 99.72%, 14 days - 99.72%, 28 days - 99.72%
<div class="serverPage-contentBox serverPage-contentBox-InlineExtra">
  <div class="serverPage-contentLabel tooltipstered" data-tooltip="Uptime сервера – процент онлайна сервера за период времени. Если у сервера uptime меньше 100%, это говорит о том, что сервер был оффлайн в какие-то периоды времени."
    data-tooltipimage="/img/icon/clock_white.svg">
    <h3 class="serverPage-contentLabelText serverPage-contentLabelText-Icon serverPage-contentLabelText-IconTime"> Uptime сегодня </h3>
  </div>
  <div class="serverPage-contentValue  tooltipstered" data-tooltip="Uptime сервера – процент онлайна сервера за период времени. Если у сервера uptime меньше 100%, это говорит о том, что сервер был оффлайн в какие-то периоды времени."
    data-tooltipimage="/img/icon/clock_white.svg"> 100 % </div>
  <div class="serverPage-contentExtra serverPage-contentExtra-Ellipsis tooltipstered" data-tooltip="Uptime за 1 день – <b>100%</b><br />за 7 дней – <b>99.71%</b><br />за 14 дней – <b>99.71%</b><br />за 28 дней – <b>99.71%</b>"
    data-tooltipimage="/img/icon/clock_white.svg"> 7 дней – <b>99.71%</b>, 14 дней – <b>99.71%</b>, 28 дней – <b>99.71%</b> </div>
</div>

List of maps
<div class="serverPage-contentSectionItem serverPage-contentSectionItem-3">
  <!-- MAPS COUNT -->
  <div class="serverPage-contentBox serverPage-contentBox-InlineExtra tooltipstered" data-tooltip="Общее количество замеченных карт на сервере за последний месяц" data-tooltipimage="/img/icon/map_white.svg">
    <div class="serverPage-contentLabel">
      <h3 class="serverPage-contentLabelText serverPage-contentLabelText-Icon serverPage-contentLabelText-IconMap"> Карт на сервере </h3>
    </div>
    <div class="serverPage-mapsCount"> 11 </div>
    <div class="serverPage-contentExtra serverPage-contentExtra-Ellipsis">
      <span class="serverPage-contentExtraLink" onclick="Tsarvar.viewServerMapsList();"> Список карт </span>
    </div>
  </div> <!-- /MAPS COUNT -->
</div>

I don’t know how to do this due to the fact that I’m still new to parsing,
how to pull out the desired text, please tell me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2020-01-21
@dimonchik2013

if the unnecessary one is always the second one - delete the second one if the
one you need has the same text - look for a piece of text
if they are both equal - look for a sign of necessity or consider them the same))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question