Page 1 of 1

how? simple_html_dom parsing webpage then insert to wp

Posted: Wed Jul 27, 2011 9:14 am
by techcai
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?

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);
} 
?>

Re: how? simple_html_dom parsing webpage then insert to wp

Posted: Wed Jul 27, 2011 8:19 pm
by techcai
i require_once('wp-load.php'); at wp_insert_post($post) can be run once.

Code: Select all

$row['FileID'] = '108804966' //get $row['FileID'] from database,it with $parseURL Form a complete Web site

$parseURL = 'http://www.tradebit.com/visit.php/71080/product/-/';

//get $row['FileID'] from database,it with $parseURL Form a complete Web site.
like this 'http://www.tradebit.com/visit.php/71080 ... /108804966'

Code: Select all

while ($row = mysql_fetch_array($results, MYSQL_ASSOC)) {
	global $post;
	parse_html($parseURL_pre . $row['FileID']);
	[b]require_once('wp-load.php');// :?:  :?:  :?: i require_once('wp-load.php'); at wp_insert_post($post) can be run once.[/b]
                wp_insert_post($post); //insert $post into wp_post table


}
why??? after i require_once('wp-load.php') the 'simple_html_dom.php' can not be use.

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);

//insert $post into wp_post table
[b]require_once('wp-load.php');// :?: i require_once('wp-load.php'); at wp_insert_post($post) can be run once[/b]
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);
} 
?>

Re: how? simple_html_dom parsing webpage then insert to wp

Posted: Thu Jul 28, 2011 6:28 am
by techcai
can anyone help me??????