且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

简单的HTML DOM解析器-发送帖子变量

更新时间:2023-02-26 10:37:28

据我所知,该文档没有提及它,但是在查看源代码后,我注意到您正在使用的函数接受一个流上下文作为其第三个参数.您可以使用以下PHP功能创建发布请求:

The documentation doesn't mention it as far as I can see, but after taking a look in the source code I noticed the function you're using accepts a stream context as its third argument. You can create a post request with this PHP feature like this:

$request = array(
'http' => array(
    'method' => 'POST',
    'content' => http_build_query(array(
        'Item' => 'Value',
        'Item2' => 'Value2'
    )),
)
);

$context = stream_context_create($request);

$html = file_get_html('http://www.google.com', false, $context);

如果您不喜欢上下文或希望使用其他方法(例如cURL扩展名),则还可以使用该方法获取页面内容,然后使用str_get_html()$parser->load()将其提供给解析器;该类本身在内部与您现在使用的方法几乎相同.

If you don't like contexts or would prefer a different method (like the cURL extension) you could also just fetch the page content using that, then feed it to the parser with str_get_html() or $parser->load(); the class itself does pretty much the same internally with the method you're using right now.