0

I'm trying to use the Simple Dom Parser to extract a piece of html from Yahoo Sports..

<?php

 include('simple_html_dom.php');

$html = file_get_html('http://sports.yahoo.com/mlb/players/5763');

$ret = $html->find('ul[class=keystats]');

print $ret;

?>

Basically i'm trying to get the Win-Loss record and ERA from the following

<ul class="keystats">            <li><strong>W-L</strong> 3-1</li>
        <li><strong>ERA</strong> 3.62</li>
        <li><strong>K</strong> 23</li>
        <li><strong>Walks</strong> 1</li>
        <li><strong>WHIP</strong> 1.04</li>
      </ul>

Its returning just "Array" when i use the code shown above, any ideas?

2
  • Well.. that gave me something but.. Array ( [0] => simple_html_dom_node Object ( [nodetype] => 1 [tag] => ul [attr] => Array ( [class] => keystats ) [children] => Array its a bunch of gibberish, 20,000+ characters worth that wouldnt fit on the page Commented May 9, 2013 at 6:14
  • yourisk.com/php/get_era.php Commented May 9, 2013 at 6:16

1 Answer 1

1

this brings anything?

$ret = $html->find("ul[class=keystats] li:first-child",0)->plaintext;
echo $ret;

you can also try this:

$ret = strip_tags($html->find("ul[class=keystats] li:first-child",0)->innertext);
echo $ret;

UPDATE:

$html = file_get_html('http://sports.yahoo.com/mlb/players/5763');

$html->find("ul[class=keystats] li strong",0)->outertext = "";
$wl = $html->find("ul[class=keystats] li",0)->innertext;
echo $wl;

$html->find("ul[class=keystats] li strong",1)->outertext = "";
$era = $html->find("ul[class=keystats] li",1)->innertext;
echo $era;
Sign up to request clarification or add additional context in comments.

2 Comments

Both produced blank pages for me
check my updated version. The trick is to first remove the <strong> tag and then read in the text. ->plaintext will work also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.