PullThePlug
Newbie
- Jun 30, 2011
- 16
- 0
I would love but i haven't 15 post yet.![]()
haha, alright dude, thanks anyway.
look forward to get to 15posts!
I would love but i haven't 15 post yet.![]()
curl "http://site-to-copy.com/page.html" -o /path/to/output-filename.html -A "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.112 Safari/534.30" --connect-timeout 30;
$ch = curl_init(" h t t p : / / e n . w i k i p e d i a . o r g / w i k i / N e w s"); // here we initializes a new curl session and we add the url from where we want to get the content. mine is
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($ch);//here we execute the given cURL session, take the page source code and store it in variable $content
$open=fopen('pagesource.txt',w) or exit("Unable to open file!");//we open the pagesource.txt file
fwrite($open, $content);//here we write the page source code from $content into our pagesource.txt file which was made earlier.
fclose($open);//close the file
$file = file_get_contents("pagesource.txt", true);//get the content of pagesource.txt file
function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
//this function will return the string between two tags :)
$content= get_string_between($file, '<span class="mw-headline" id="Etymology">Etymology</span></h2>', '<sup id="cite_ref-1" class="reference">< a href="#cite_note-1"><span>[</span>2<span>]</span></a></sup>');
//To get the content we need two delimiters.
//So you see that our Etymology paragraph(from here: h t t p : / / e n . w i k i p e d i a . o r g / w i k i / N e w s) it start with "One theory is that news.." and ends with "..the cardinal directions: north, east, west, and south". Ok, now go to our pagesource.txt and search these two strings. Our delimitors will be the tags before "One theory is that news.."(which is <span class="mw-headline" id="Etymology">Etymology</span></h2>) and the tags after the "..the cardinal directions: north, east, west, and south" (in our case "<sup id="cite_ref-1" class="reference">< a href ="#cite_note-1"><span>[</span>2<span>]</span></a></sup>"). You can choose whatever delimitors you want. :D
echo $content; // print the result
hey guys, been getting a few PMs about this, will be better for everyone if we keep it here in the topic so others can help/learn as well ......
Done! This is a very simple example and u can expand on it to suit ur needs![]()
Ok, here is an little exemple:
I choose this page: h t t p : / / e n . w i k i p e d i a . o r g / w i k i / N e w s. Let's say that we want to take the content from Etymology paragraph.
First make a new PHP file called "getpagesource.php"(or whatever you want, doesn't matter the name) and a new .txt file called "pagesource.txt".
In it add the next code....