NFL Final Score Results Project

I’m a beginner at this so bare with me. I would like to have my web page automatically get the FINAL NFL football scores from some other site automatically via php scripting in order to calculate football pool results. I haven’t found a site that lists the actual winners directly but they all pretty much display the final score results which means the data would need to be parsed in a clever way. I’m thinking that there is probably a site out there that has this data in the format I want. I just haven’t found it yet. I’m looking for a little direction and advise on tackling this project. Right now my idea is strip tags from a given website and stuff the raw data into an array for processing. What I don’t know is how to just get the relevant data so there is not a lot of garbage in there.

The manual way I did this in the past was to simply use excel to total up the number of incorrect picks for each person and after the games were over I would have to manually delete the column of each team that won so the number of incorrect picks would be updated to reveal that weeks winner of the pool. That worked OK but it certainly wasn’t automatic and still required more time than I wanted to spend on it.

I have already got the general look of the table close to the way I want it and you can see from This Code Example of initial static data that once the winning teams are determined, then all I need to do is remove the data from the respective columns so the number of incorrect picks can update. The trick is to get the winning teams to automatically register via another site and do all of the calculations automatically on the server side. Php seems like it would work well here to dynamically update the results.

I’m just looking for guidance here as I know this is fairly complicated for a beginner like me. I’m learning the basics right now so I’m not up to speed on all of the available functions and methods but I have some time before the regular season starts to make this happen. Just need any ideas or suggestions on where to go with this.

Well the first question is whether you have permission to scrap these other sites. Once that confirmed you can than proceed to create a strategy to scrap the sites. Your best bet for that would be using something like DOM Crawler or [url=http://querypath.org/]Query Path to crawl the HTML pages and extract data. In particular both libraries make it easier to crawl/process HTML/XML than standard PHP solutions such as; DOMDocument or Simple XML.

I just spent the past few days learning a little Query Path to get the winning teams from any given Sunday night during football season. I also learned what web scraping is, very interesting. Using Query Path really made this task surprisingly easy to do. So I just wanted to thank oddz for pointing me in the right direction and getting the ball rolling. Here is the specialized code that works with one specific site listed in the code. I noticed that the

b

tags were unique in the

table.sbgame

selector so it made getting the required info straight forward. On other sites it’s not as easy but I’m going to make it work on other sites as well just in case. For now I just copied the whole thing into one of my project directories just to get it working.


<!DOCTYPE HTML>
<html>
<head>
     <meta charset="UTF-8">

<?php 
	$fb_year = 2012;
	$fb_week = 2;
	$title = '<title>Getting Winning Football Teams For ' . $fb_year;
	$title .= ' Week ' . $fb_week . ' </title>';
	echo "$title";
?>

</head>
<body>

	<?php
	require 'querypath-master\\src\\qp.php';
	$count = 1;
	$fb_year = 2012;
	$fb_week = 2;
	$active_site = 'http://www.footballdb.com/scores.html?lg=NFL&yr=2012&type=reg&wk=';
	$active_site .= "$fb_week";
	echo '<h3>' . $fb_year . ' Week ' . $fb_week . ' Winning Teams</h3><hr width=250px align=left>';
	$qp = htmlqp("$active_site");

	foreach($qp->find('table.sbgame a>b') as $winner) {
		echo 'Game ' . $count . '  ' . $winner->text() . '<br>';
		++$count;
	}

	unset($winner);
	unset($count);
	?>


</body>
</html>

If there are any of you who have installed this QueryPath library before, is there any special way to install this so all the examples and documentation work? I wanted to use the pear install method but I couldn’t figure out how to do it in windows. It looks like it was made to be done in Linux looking at the README file. Also I’ve never used Github before so that’s throwing me off a little. I’m using WAMP on Windows7 for the time being. I just want to make sure I installed it right.