【发布时间】:2017-03-16 16:01:00
【问题描述】:
我想获取 html 代码并从网站上查找,我正在使用此代码执行此操作但出现错误
《curl和htmldomparser的同时使用》
致命错误:在第 46 行的 C:\cod.php 中的字符串上调用成员函数 find()
线路错误:
foreach ($content->find('div[class=postbody]') as $element)
我能够使用登录获得完整的源代码 但问题是:
foreach ($content->find('div[class=postbody]') as $element)
这条鳕鱼:
include_once('/simple_html_dom.php');
error_reporting(E_ALL);
function vBulletinLogin($username,$password,$url,$posturl){
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER,false);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'veri.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'veri.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_COOKIESESSION,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_REFERER, $url.'index.php');
curl_setopt($ch, CURLOPT_URL, $url.'login.php?do=login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "vb_login_username=$username&vb_login_password&s=&securitytoken=guest&do=login&vb_login_md5password=".md5($password)."&vb_login_md5password_utf=".md5($password));
$exec = curl_exec($ch);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_REFERER, $url.'login.php?do=login');
curl_setopt($ch, CURLOPT_URL, $url.'clientscript/vbulletin_global.js?v=373');
$exec = curl_exec($ch);
curl_setopt($ch, CURLOPT_REFERER, $url.'login.php?do=login');
curl_setopt($ch, CURLOPT_URL, $url.'index.php');
$exec = curl_exec($ch);
curl_setopt($ch, CURLOPT_REFERER, $url.'index.php');
curl_setopt($ch, CURLOPT_URL, $posturl);
$exec = curl_exec($ch);
curl_close($ch);
return $exec;
}
$content = vBulletinLogin('user','pass','url','url');
foreach ($content->find('div[class=postbody]') as $element)
{
echo $element;
}
【问题讨论】:
-
$content是一个 string 而find方法显然需要别的东西。您是否尝试过阅读手册? -
不,我不需要手动。/我如何从“查找”中使用。/或如何转换 $content
-
这个怎么样:
return str_get_html($exec); -
我使用 [str_get_html] 和 [file_get_html] 但输出为空