Jump to content

Recommended Posts

Hi,
I'm trying to pull data for a few players from another site. This is NOT for commercial use..Anyway, I want to pull the following info:

Player name, jersey number, position, team, height, weight, birthdate...and then later on their career stats.

So far this is what I have (this only works for the player name, jersey number and position so far):

[code]<?php

for($count=6619;$count<=6619;$count++) {

/*** Load the page here ***/

$input = file_get_contents("http://sports.yahoo.com/mlb/players/{$count}/career");

// *** Finding the info, First Name, Last Name, Jersey Number, Position ***/

preg_match('@(?<="yspsctnhdln"\>)([^<]+)<\/span>\s*#(\d+)\s([^<]+)\s([^<]+)\s@ism', $input, $info);

$name = explode(" ", $info[1]);
$jersey = trim($info[2], "  |  ");
$initialposition = explode("/", $info[3]);
$position = trim($initialposition[0], "  |  ");
$team = explode(" ", $info[4]);

preg_match('@<span class="yspscores" style="line-height:140%;">([.]+)\sWeight:([^<]+)<br>\s</span>@i', $input, $match);

$height = explode("Height:", $match[1]);
$weight = explode("     ", $match[2]);

/*** DISPLAYING IT HERE ***/
echo '<table>';
echo
"<tr><td>{$count}</td><td>{$name[0]}</td><td>{$name[1]}</td><td>{$jersey}</td><td>{$position}</td><td>{$match[2]}</td></tr>";
echo '</table>';
}
?>[/code]

I know I messed up the heigh, weight and team regex,etc. I was hoping someone coulc point me in the right direction. Heres the html:

Player name, jersey , position and team html to parse
[code]<b><span class="yspsctnhdln">Albert Pujols</span>
            #5   |  
             First Base/Left Field   |  
      <a href="http://us.lrd.yahoo.com/_ylt=AiO5aw3ziz_LLaUn2BcY.qiFCLcF/SIG=11ajpqctg/**http%3a//sports.yahoo.com/mlb/teams/stl" >St. Louis Cardinals</a></b></td>
             <td align="right" class="yspgens">[/code]

height, weight, birthdate html to parse:
[code]        <span class="yspscores" style="line-height:140%;">
      Height: 6-3      
      Weight: 225<br>
      Bats: R      
      Throws: R<br>
      Born: Jan 16, 1980 - Santo Domingo, Dominican Republic<br>

      College: Maple Woods (MO) CC<br>

      Draft: 1999 - 13th round by the St. Louis Cardinals
            <br></span>[/code]
Link to comment
https://forums.phpfreaks.com/topic/5211-regex-preg_match-help/
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.