Javascript 如何将simple_html_dom与phantomjs一起使用
我正在尝试让这两个库相互协作我当前的代码如下所示: phantomjs.js scraper.php 我得到的回报是:Javascript 如何将simple_html_dom与phantomjs一起使用,javascript,php,phantomjs,simple-html-dom,php-phantomjs,Javascript,Php,Phantomjs,Simple Html Dom,Php Phantomjs,我正在尝试让这两个库相互协作我当前的代码如下所示: phantomjs.js scraper.php 我得到的回报是: Warning: strlen() expects parameter 1 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 91 Warning: strlen() expects parameter 1 to be string, array given
Warning: strlen() expects parameter 1 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 91
Warning: strlen() expects parameter 1 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1139
Warning: strlen() expects parameter 1 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1149
Warning: preg_match_all() expects parameter 2 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1620
Warning: strlen() expects parameter 1 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1632
Warning: preg_match_all() expects parameter 2 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1620
Warning: strlen() expects parameter 1 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1632
Warning: preg_match_all() expects parameter 2 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1620
Warning: strlen() expects parameter 1 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1632
Warning: preg_match_all() expects parameter 2 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1620
Warning: strlen() expects parameter 1 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1632
Warning: preg_match_all() expects parameter 2 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1620
Warning: strlen() expects parameter 1 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1632
Warning: preg_match_all() expects parameter 2 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1620
Warning: strlen() expects parameter 1 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1632
Warning: preg_match_all() expects parameter 2 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1620
Warning: strlen() expects parameter 1 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1632
Warning: preg_match_all() expects parameter 2 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1620
Warning: strlen() expects parameter 1 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1632
Warning: preg_match_all() expects parameter 2 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1620
Warning: strlen() expects parameter 1 to be string, array given in D:\XAMPP\htdocs\assets\php\simple_html_dom.php on line 1632
返回错误的简单\u html\u dom函数:
// remove noise from html content
// save the noise in the $this->noise array.
protected function remove_noise($pattern, $remove_tag=false)
{
global $debugObject;
if (is_object($debugObject)) { $debugObject->debugLogEntry(1); }
$count = preg_match_all($pattern, $this->doc, $matches, PREG_SET_ORDER|PREG_OFFSET_CAPTURE);
for ($i=$count-1; $i>-1; --$i)
{
$key = '___noise___'.sprintf('% 5d', count($this->noise)+1000);
if (is_object($debugObject)) { $debugObject->debugLog(2, 'key is: ' . $key); }
$idx = ($remove_tag) ? 0 : 1;
$this->noise[$key] = $matches[$i][$idx][0];
$this->doc = substr_replace($this->doc, $key, $matches[$i][$idx][1], strlen($matches[$i][$idx][0]));
}
// reset the length of content
$this->size = strlen($this->doc);
if ($this->size>0)
{
$this->char = $this->doc[0];
}
}
当我使用
var\u dump($output)
时,我得到了站点的html,因此我知道该命令正在工作,但simple\u html\u dom似乎不接受它 问题是:$output
是数组,但是str\u get\u html
需要一个字符串作为参数。因此,请确保在解析$output之前将其转换为字符串。问题在于:$output
是数组,但str\u get\u html
需要字符串作为参数。因此,请确保在解析$output之前将其转换为字符串。类似于:
$body = `phantomjs myscript.js`;
$doc = str_get_html($body);
您可能需要在phantomjs脚本中设置超时,因为您没有给dom太多的加载时间。类似于:
$body = `phantomjs myscript.js`;
$doc = str_get_html($body);
您可能需要在phantomjs脚本中设置超时,因为您没有给dom太多的加载时间。看看“scraper.php”,我有与您提供的完全相同的代码,请尝试使用backticks。Backticks在每种脚本语言中的工作方式都是相同的。请看“scraper.php”,我有与您提供的完全相同的代码,请尝试使用Backticks。Backticks在每种脚本语言中的工作方式都是相同的。结果证明这就是答案。把这个:
$output=内爆(“”,$output)
在str\u get\u html
解决问题之前,原来这就是答案。把这个:$output=内爆(“”,$output)
beforestr\u get\u html
解决了这个问题
$body = `phantomjs myscript.js`;
$doc = str_get_html($body);