Jump to content

Parse data from website

Recommended Posts


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: 



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 post
Share on other sites

or there is simple_html_dom EG

include 'simple_html_dom.php';

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

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

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>";


Ayarith - 59 seconds ago
Indirarc - 54 seconds ago


Link to post
Share on other sites

Join the conversation

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

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.