Is there a script to do that ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
grgo
Forum Newbie
Posts: 6
Joined: Fri Jun 06, 2008 3:49 pm

Is there a script to do that ?

Post by grgo »

Hy,
I wonder is there a script that would pull data from some page which is updated every few hours. Data are always in the same table, so I was thinking i would tell the program at which part table or text begins, and ends, and than it would save it in txt file, which I could use.
Thanks, G
LBmtb
Forum Newbie
Posts: 23
Joined: Wed May 14, 2008 11:14 am

Re: Is there a script to do that ?

Post by LBmtb »

Scraping makes the baby bunnies' cry.
calcop
Forum Newbie
Posts: 20
Joined: Fri Mar 04, 2005 2:13 pm

Re: Is there a script to do that ?

Post by calcop »

Yes, this can easily be done with curl and preg_match.

Here are some good examples to check out on how to use the two libs:

http://www.php.net/manual/en/book.curl.php
http://www.php.net/manual/en/book.pcre.php
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Is there a script to do that ?

Post by Kieran Huggins »

simpleXML might be a better tool than regex in this case.
grgo
Forum Newbie
Posts: 6
Joined: Fri Jun 06, 2008 3:49 pm

Re: Is there a script to do that ?

Post by grgo »

Thanks, but is there any program to do that or I have to learn code, or hire somebody do that for me ?
grgo
Forum Newbie
Posts: 6
Joined: Fri Jun 06, 2008 3:49 pm

Re: Is there a script to do that ?

Post by grgo »

I have found this simple tutorial:
http://www.oooff.com/php-scripts/basic- ... arsing.php

but don't know why it doesnt work, looks like this:
<?php
$data = file_get_contents('http://search.msn.com/results.aspx?q=site%3Afroogle.com');
$regex = '/1-10 of (.+?) results/';
preg_match($regex,$data,$match);
var_dump($match);
echo $match[1];
?>

then I tried to pull title and put this together:
<?php
$data = file_get_contents('http://www.najdi.si');
$regex = '/<title> (.+?) </title>/';
preg_match($regex,$data,$match);
var_dump($match);
echo $match[1];
?>
And doesnt work as well ??
Post Reply