Import all your facebook posts into a database

 
Written By Sanjir Habib On Dec-22nd, 2017

Go to facebook settings and find the “Download a copy of your facebook data” link.

Extract the zip and find a file called timeline.htm in html folder.

Process this data with a PHP script like this


$in='timeline.htm';
$doc=new DOMDocument();
@$doc->loadHTML(file_get_contents($in));
$xp=new DOMXpath($doc);
$xp->preserveWhiteSpace=false;
$date='';
$body='';
foreach($xp->query("//div[@class='meta' or @class='comment']") as $v){
    $class=$v->getAttributeNode("class")->value;
    $val=$v->nodeValue;
    if($class=='meta'){
        $date=$val;
        continue;
    }
    else $body=$val;
    // here you have the data in $date and $body fields.
    // insert these into your database
    // sql ... insert into table $date, $body
}