Jump to content

Parse data from website


Erriko

Recommended Posts

Hello!

I would like to grab data from a website. What I want is to take the name and time and output it like following:

 

Ayarith 59 seconds

Indirarc 54 seconds

 

The data is taken from an online game with the following link: 

https://medivia.online/community/online/legacy

 

Exemple data from this link:

<li><div class="med-width-25">59 seconds ago</div><div class="med-width-35"><a href="/community/character/Ayarith">Ayarith</a></div><div class="med-width-15">Druid</div><div class="med-width-25 med-text-right med-pr-40">32</div></li>

<li><div class="med-width-25">54 seconds ago</div><div class="med-width-35"><a href="/community/character/Indirarc">Indirarc</a></div><div class="med-width-15">Druid</div><div class="med-width-25 med-text-right med-pr-40">20</div></li>

 

I hope you can help me out!

Link to comment
Share on other sites

or there is simple_html_dom EG

include 'simple_html_dom.php';

$str = '
        <body>
        <ul>
            <li>
                <div class="med-width-25">59 seconds ago</div>
                <div class="med-width-35">
                    <a href="/community/character/Ayarith">Ayarith</a>
                </div>
                <div class="med-width-15">Druid</div>
                <div class="med-width-25 med-text-right med-pr-40">32</div>
            </li>

            <li>
                <div class="med-width-25">54 seconds ago</div>
                <div class="med-width-35">
                    <a href="/community/character/Indirarc">Indirarc</a>
                </div>
                <div class="med-width-15">Druid</div>
                <div class="med-width-25 med-text-right med-pr-40">20</div>
            </li>
        </ul>
        </body>
       ';
$html = new simple_html_dom();
$html->load($str);

foreach ($html->find('li div a') as $a) {                      // find link elements that are nested inside a div inside a listitem
    $name = $a->plaintext;
    $time = $a->parent()->parent()->children(0)->plaintext;    // navigate to the enclosing listitem's first div
    echo "<b>$name</b> - $time<br>";
}

outputs

Ayarith - 59 seconds ago
Indirarc - 54 seconds ago

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.