Why is this ‘include(‘wp-load.php’)’ with ‘include(‘simple_html_dom.php’)’ will have a conflict???
include ‘wp-load.php’ for run function wp_insert_post($post) ,
but once include ‘wp-load.php’ ,the parse function can not to run that in ‘simple_html_dom.php’.
<?php
//include(‘wp-load.php’); //include ‘wp-load.php’ for run function wp_insert_post($post)
include(‘simple_html_dom.php’);
hi felgall, thanks your reply.
when i enable include wp-load, simple html don cannot work, it throw error below.
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 include wp-load, the simple html dom worked very well. but it throw error below:
Fatal error: Call to undefined function wp_insert_post() in C:\wamp\www\ estinclude.php on line 26
function wp_insert_post() cannot to work for it need wp-load.
‘wp-load.php’)’ with ‘include(‘simple_html_dom.php’)’ have a conflict.
I have no idea why there is a conflict. I’ve never mixed Simple HTML DOM and WordPress before and I’m not surprised that a conflict arises. WP is a massive beast and it is inevitable that it will conflict with something. You have two options:
Stop trying to drag in WP and just insert the post into the database via some other means.
Move the web scraping part of the code into a separate file (e.g. ‘webscraper.php’) and use something like file_get_contents(“http://yourserver.com/path/to/webscraper.php”); to extract the content from the code that drags in WP.
I would personally do #1 just because I’m used to it. But #2 is probably “more correct” - albeit a lot slower.
@felgall - ‘wp-load.php’ is the main WordPress loader script. You can include it from within the web server environment and then have access to all of the primary WP functionality. Useful for running cron scripts for newbies to WP but chugs RAM like nothing else.
‘simple_html_dom.php’ is Simple HTML DOM. It makes parsing web scraped content super easy with its jQuery-like selector syntax. Infinitely better than trying to use preg_match(). I just got done making a web scraping toolkit that happens to include this library.