html - PHP parsing won't find "span" tags -
i'm trying find span tags on website similar this: http://www.pointstreak.com/prostats/leagueschedule.html?leagueid=49&seasonid=14225. tags need these:

however, when use code such following:
$my_url = 'http://www.pointstreak.com/prostats/leagueschedule.html?leagueid=49&seasonid=14225'; $html = file_get_contents($my_url); $dom = new domdocument(); $dom->loadhtml($html); $xpath = new domxpath($dom); //put xpath query here $my_xpath_query = "//span"; $result_rows = $xpath->query($my_xpath_query); // create array hold content of nodes $statslistings = array(); //here loop through our results (a domdocument object) foreach ($result_rows $result_object) { $statslistings[] = $result_object->nodevalue; } echo json_encode($statslistings); the output [].
if replace $statslistings[] = $result_object->nodevalue; $statslistings[] = $result_object->childnodes->item(0)->nodevalue;, still same [] output. when there span tags values, why getting nothing?
xpath not guilty @ all. span tags added dinamically. have @ source code of page, not dom-structure, may modified javascript, use "view-source:" , see same html, parsed xpath.
it idea have @ table class tablelines? probably, have there may need. should skip "maincolor" , "tableheader", , start processing "light" class.
<table width="98%" class="tablelines" cellpadding="2" border="0" cellspacing="1"> <tr class="maincolor"> <td colspan="8" align="right">all times local</td> </tr> <tr class="tableheader"> <td width="4%"> <b>gn</b> </td> <td nowrap width="21%"> <b>away</b> </td> <td nowrap width="21%"> <b>home</b> </td> <td width="14%"><b>date</b></td> <td width="11%"><b>time</b></td> <td width="8%"><b>score</b></td> <td nowrap align="right" width="*"><b>boxscore</b></td> <td nowrap align="center" width="4%"><b>gs</b></td> </tr> <tr class="light"> <td></td> <td><a href="teamplayerstats.html?teamid=3138&seasonid=14225">sioux city</a> <b>1</b></td> <td><a href="teamplayerstats.html?teamid=3139&seasonid=14225">sioux falls</a> <b>5</b></td> <td>tue, apr 14</td> <td> 7:05 pm</td> <td> <b>1 - 5</b> </td> <td align="right"> <a href="http://www.pointstreak.com/flashapp/index_hockey_new.html?gameid=2657671" target="_blank"><img src="/images/gamelive_icon.gif" title="click here game live!" alt="click here game live" border="0"></a> <a href="boxscore.html?gameid=2657671">final</a></td> <td align="center"> <a href="gamesheet_full.html?gameid=2657671" target="_blank"><img src="/images/playersection/prostats/gslink.gif" border="0"></a> </td> </tr> for example, try this:
$my_url = 'http://www.pointstreak.com/prostats/leagueschedule.html?leagueid=49&seasonid=14225'; $html = file_get_contents($my_url); $dom = new domdocument(); $dom->loadhtml($html); $xpath = new domxpath($dom); //put xpath query here $my_xpath_query = "//tr[@class='light']/td"; $result_rows = $xpath->query($my_xpath_query); echo $result_rows->length; // create array hold content of nodes $statslistings = array(); //here loop through our results (a domdocument object) foreach ($result_rows $result_object) { $statslistings[] = $result_object->nodevalue; } echo json_encode($statslistings); probably have found need, , in nice json form: http://www.pointstreak.com/ajax/trending_ajax.html?action=divisionscoreboard&divisionid=12299&seasonid=14225
{"trending_list":null,"lacrosse_list":null,"hockey_list":null,"soccer_list":null,"baseball_list":null,"softball_list":null,"basketball_list":null,"news_list":null,"news_hockey_list":null,"news_baseball_list":null,"news_baseball_list2":null,"news_softball_list":null,"news_basketball_list":null,"games_list":[{"status":"final","hometeam":"sioux falls","homescore":"4","awayteam":"muskegon","awayscore":"2","timeremaining":"0:00","currentperiod":"3rd","schedtime":"7:05 pm","gamedate":"15\/05","link":"..\/prostats\/boxscore.html?gameid=2672134"},{"status":"final","hometeam":"muskegon","homescore":"1","awayteam":"sioux falls","awayscore":"6","timeremaining":"0:00","currentperiod":"3rd","schedtime":"7:15 pm","gamedate":"10\/05","link":"..\/prostats\/boxscore.html?gameid=2672133"},{"status":"final","hometeam":"muskegon","homescore":"2","awayteam":"sioux falls","awayscore":"3","timeremaining":"0:00","currentperiod":"1st","schedtime":"7:15 pm","gamedate":"09\/05","link":"..\/prostats\/boxscore.html?gameid=2672132"},{"status":"final","hometeam":"dubuque","homescore":"3","awayteam":"muskegon","awayscore":"4","timeremaining":"0:00","currentperiod":"3rd","schedtime":"7:05 pm","gamedate":"05\/05","link":"..\/prostats\/boxscore.html?gameid=2662061"},{"status":"final","hometeam":"muskegon","homescore":"0","awayteam":"dubuque","awayscore":"6","timeremaining":"0:00","currentperiod":"3rd","schedtime":"7:15 pm","gamedate":"02\/05","link":"..\/prostats\/boxscore.html?gameid=2662060"},{"status":"final","hometeam":"sioux falls","homescore":"7","awayteam":"tri-city","awayscore":"3","timeremaining":"0:00","currentperiod":"3rd","schedtime":"7:05 pm","gamedate":"02\/05","link":"..\/prostats\/boxscore.html?gameid=2662055"},{"status":"final","hometeam":"muskegon","homescore":"3","awayteam":"dubuque","awayscore":"1","timeremaining":"0:00","currentperiod":"3rd","schedtime":"7:15 pm","gamedate":"01\/05","link":"..\/prostats\/boxscore.html?gameid=2662059"},{"status":"final","hometeam":"sioux falls","homescore":"4","awayteam":"tri-city","awayscore":"3","timeremaining":"0:00","currentperiod":"3rd","schedtime":"7:04 pm","gamedate":"01\/05","link":"..\/prostats\/boxscore.html?gameid=2662054"},{"status":"final","hometeam":"tri-city","homescore":"2","awayteam":"sioux falls","awayscore":"3","timeremaining":"0:00","currentperiod":"3rd","schedtime":"7:05 pm","gamedate":"29\/04","link":"..\/prostats\/boxscore.html?gameid=2664638"},{"status":"final","hometeam":"dubuque","homescore":"7","awayteam":"muskegon","awayscore":"3","timeremaining":"0:00","currentperiod":"3rd","schedtime":"7:05 pm","gamedate":"25\/04","link":"..\/prostats\/boxscore.html?gameid=2662058"}],"division_list":null,"site_network_title":null,"leagueshortname":"ushl","includesportlink":null,"showleaguename":0}
Comments
Post a Comment