问题描述
在我的项目中,我使用通过composer安装的最新htmlsimpledom。我的curl脚本正在登录外部b2b页面并返回html。问题是我无法用html_simple_do
m来处理它,因为在处理html之后,加载函数显示为null。这是我的代码:
// html看起来像这样(用dd()-laravel显示):
simple_html_dom:
public function __construct()
{
$this->client = new \simplehtmldom\HtmlWeb();
}
private function login()
{
$site1 = $curl->get_data_curl('https://main.b2b.somedomain.pl/pl/user/home',$data); //it's html from image above
$getData = $this->client->load($site1); // this cause NULL
$fields = $getData->find("input[id=username]"); // this throw error because null above
}
我不确定导致问题的原因,因为在我的服务器上有一段旧代码,其中通过html_simple_dom
处理的html相同,但是使用的是非常老版本的代码,例如从2012〜开始,并且没有对象方式(使用str_get_html()
)
非常感谢您的帮助,祝您有愉快的一天。
更新:
调用$this->client->load('<html><body>Hello!</body></html>');**
也会导致null
解决方法
对于有相同问题的未来开发者:
更改:
new \simplehtmldom\HtmlWeb();
收件人:
new \simplehtmldom\HtmlDocument();