<?php
$url="http://www.imdb.com/nowplaying/";
$beg="<td class="movie ">";
$end="</a>";
$data = file_get_contents($url);
$regex = '/'.$beg.'(.+?)'.$end.'/';
$count=1;
preg_match_all($regex,$data,$match,PREG_SET_ORDER);
foreach ($match as $result) {
$link = $result[1];
$link=strip_tags($link);
echo $link . '<br>';
}
?>
Per some requests in another thread for a copy and past code segment to automatically scrape a given page. Here was an example of someone wanting to scrape the now playing movie titles from IMDB, using this code you get the following result.
http://answerexpert.net/movies.php
Code:<?php $url="http://www.imdb.com/nowplaying/"; $beg="<td class="movie ">"; $end="</a>"; $data = file_get_contents($url); $regex = '/'.$beg.'(.+?)'.$end.'/'; $count=1; preg_match_all($regex,$data,$match,PREG_SET_ORDER); foreach ($match as $result) { $link = $result[1]; $link=strip_tags($link); echo $link . '<br>'; } ?>
Just put that anywhere on a php page and it will automatically scrape the given page every time the page is loaded.
To use this for other pages just change the first 3 lines url, beg, and end
Thanks for this. But it is getting me error i tried it here http://kojakdirectory.com/scrape.php
<?php
$url="http://www.imdb.com/nowplaying/";
$beg="<td class="movie ">";
$end="</a>";
$data = file_get_contents($url);
$regex = '/'.$beg.'(.+?)'.$end.'/';
$count=1;
preg_match_all($regex,$data,$match,PREG_SET_ORDER);
foreach ($match as $result) {
$link = $result[1];
$link=strip_tags($link);
echo $link . '<br>';
}
?>
$end="<div id="nowplaying-media-strip">";
Thats what i thought but kept getting a blank page. I'll have to keep playing with it tomorrow. Thanks for your help
Great info NETA10.
do you think its possible to have more than 1 variable?
like this:
<string1>...<string11>{text I}<string22>...<string111>{text II}<string222>...<string2>
-to define the strings and to output the text I and II in a template.
I could work on something like that for you, could you post here or pm me a page/uRL and an example of what you'd like to scrape so I can test?
Thanks