-
May 20th, 2012, 01:39 PM
#1
Parsing Website for data
Hey all
I want to parse this financial website and input the data onto my server. This is so i can then display it on my android easily. I have the following which is working just fine but i cant get it to display all the data i want.
Code:
<?php
$content = file_get_contents('http://finance.yahoo.com/q?s=fb&ql=1');
preg_match('#<span id="yfs_l84_fb">(.*)</span></span>#', $content, $match);
$price = $match[1];
preg_match('#<span id="yfs_l86_fb">(.*)</span></span></p></div>#', $content, $match);
$after = $match[1];
?>
<body bgcolor="#000">
<font color="red">
<table border="1" name="quote">
<tr>
<td><font color="red">
Current Price:
</font>
</td>
<td>
<font color="#0099FF">
<?php
echo "$price";
?>
</font>
</tr>
</td>
<tr>
<td><font color="#190fff">
After Hours:
</td>
<td>
<font color="#0099FF">
<?php
echo "After Hours: $after";
?>
</td>
</tr>
</table>
</font>
I would like to just grab the price and percent down/up but when i try to do that it just breaks it. anyone have any suggestion on alternative or anything else.. The above code is sloppy i know. but when done it will be PRETTY
New to PHP and MySql. Started looking at scripts about a week ago. So far have very little understanding of it. So please be easy with me if I ask a stupid question.
www.ethans-space.com
-
May 20th, 2012, 03:10 PM
#2
Re: Parsing Website for data
Remember that "/" is a regular expression modifier. You have to escape it in any pattern.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
May 20th, 2012, 04:09 PM
#3
Re: Parsing Website for data
Originally Posted by PeejAvery
Remember that "/" is a regular expression modifier. You have to escape it in any pattern.
Could you show me an example of what you mean
New to PHP and MySql. Started looking at scripts about a week ago. So far have very little understanding of it. So please be easy with me if I ask a stupid question.
www.ethans-space.com
-
May 20th, 2012, 06:48 PM
#4
Re: Parsing Website for data
Example is here: http://ellucidstudios.com/grabber.php
I want to split up the info into different tables but when i try it gives me blank data.
New to PHP and MySql. Started looking at scripts about a week ago. So far have very little understanding of it. So please be easy with me if I ask a stupid question.
www.ethans-space.com
-
May 20th, 2012, 09:29 PM
#5
Re: Parsing Website for data
Originally Posted by davidjmorin
Could you show me an example of what you mean
Yes...you're patterns are invalid for matching.
PHP Code:
/<span id="yfs_l84_fb">(.*?)<\/span><\/span>/i
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
May 22nd, 2012, 07:56 AM
#6
Re: Parsing Website for data
Originally Posted by PeejAvery
Yes...you're patterns are invalid for matching.
PHP Code:
/<span id="yfs_l84_fb">(.*?)<\/span><\/span>/i
hey man. Yea that worked for a bit. for some reason this morning its not displaying anything at all. I read up on redex last night and thought i had a grasp of it but apparently im missing something. How can i get it so that it finds the span mentioned in code regardless of whitespace/breaks/etc. I think that might be my issue as the page code changes daily but not the ID.
Code:
<?php
$content = file_get_contents('http://finance.yahoo.com/q?s=fb&ql=1');
$fb = file_get_contents('http://www.cbssports.com/mlb/teams/page/BOS/boston-red-sox');
$wod = file_get_contents('http://www.wordthink.com');
preg_match('/<span id="yfs_l84_fb">(.*?)<\/span> <\/span>/i', $content, $match);
$price = $match[1];
preg_match('/<table class="data" width="100%" >(.*?)<\/b><\/td><\/tr><\/table>/i', $fb, $match);
$fbs = $match[1];
preg_match('/<b>(.*?)<\/b>/', $wod, $match);
$wod1 = $match[1];
preg_match('/<i>(.*?)<\/p>/', $wod, $match);
$wod2 = $match[1];
?>
<head>
<style type="text/css">
a.link
{
color: #fff;
}
a:link {color: #fff; text-decoration: underline; }
a:active {color: #fff; text-decoration: underline; }
a:visited {color: #ff0000; text-decoration: underline; }
a:hover {color: #ff0000; text-decoration: none; }
</style>
</head>
<body bgcolor="#1C2F2F">
<font color="red">
Facebook Stock Prices:
<table border="1" name="quote">
<tr>
<td><font color="red">
Current Price:
</font>
</td>
<td>
<font color="#0099FF">
<?php
echo "$price";
?>
</font>
</tr>
</td>
</table>
<br />
<table width="500px">
<tr color="white"><td>
Boston Redsox Scores:
<?php
echo "$fbs";
?>
</font>
</tr></td></table>
</font>
<br /><br />
<font color="#ff0000">
<u>
<?php
echo "$wod1";
?>
<b>:</b></font></u><font color="#fff">
<?php
echo "$wod2";
?></font>
New to PHP and MySql. Started looking at scripts about a week ago. So far have very little understanding of it. So please be easy with me if I ask a stupid question.
www.ethans-space.com
-
May 22nd, 2012, 10:26 AM
#7
Re: Parsing Website for data
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|