Erriko Posted October 15, 2020 Share Posted October 15, 2020 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! Quote Link to comment https://forums.phpfreaks.com/topic/311606-parse-data-from-website/ Share on other sites More sharing options...
gw1500se Posted October 16, 2020 Share Posted October 16, 2020 This is what you need. Quote Link to comment https://forums.phpfreaks.com/topic/311606-parse-data-from-website/#findComment-1581928 Share on other sites More sharing options...
Barand Posted October 16, 2020 Share Posted October 16, 2020 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 Quote Link to comment https://forums.phpfreaks.com/topic/311606-parse-data-from-website/#findComment-1581933 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.