how? simple_html_dom parsing webpage then insert to wp
Posted: Wed Jul 27, 2011 9:14 am
help me!
i think parsing a webpage then insert contents into wordpress wp_post table.
but, when i require('wp-load.php'); it throw Fatal error: Call to a member function find() on a non-object in C:\wamp\www\simple_html_dom.php on line 879.
when i disable //require('wp-load.php'); it throw Fatal error: Call to undefined function wp_insert_post() in C:\wamp\www\testinclud.php on line 22
the wp_insert_post($post); can not to run, why?
i think parsing a webpage then insert contents into wordpress wp_post table.
but, when i require('wp-load.php'); it throw Fatal error: Call to a member function find() on a non-object in C:\wamp\www\simple_html_dom.php on line 879.
when i disable //require('wp-load.php'); it throw Fatal error: Call to undefined function wp_insert_post() in C:\wamp\www\testinclud.php on line 22
the wp_insert_post($post); can not to run, why?
Code: Select all
<?php
//require('wp-load.php');
require('simple_html_dom.php');
ini_set("max_execution_time",0);
$post = array();
$post['post_status'] = 'publish';
$post['post_author'] = 1;
$post['comment_status'] = 'closed';
//$post['post_category'] = array(6);
$post['post_date'] = date('Y-m-d H:i:s',strtotime("now"));
$post['post_content'] = '';
$parseURL = 'http://www.tradebit.com/visit.php/71080/product/-/108804966';//this site will be parse
parse_html($parseURL);
echo '$post post_content ' . $post['post_content'] . '<br>';
echo 'title' . '<br>';
echo $post['post_title'] . '<br>';
//insert $post into wp_post table
wp_insert_post($post);
/**
parsing webpage
@param string $parseURL
@return $post, this $post will be insert into wp_post table
*/
function parse_html($parseURL){
global $post;
$html = new simple_html_dom();
$html->load_file($parseURL);
foreach($html->find('title') as $element) {
$title = preg_split ( '/ - /', $element->plaintext);
}
$post['post_title'] = $title[0];
$post['post_content'] .= $html->find('div[class=orangeContent]',1); # get orangeContent as post_content
return $post;
// tear down
$html->clear();
unset($html);
}
?>