Simple HTML DOM Parser - Send post variables

前端 未结 1 628
隐瞒了意图╮
隐瞒了意图╮ 2021-01-06 00:46

I have the Simple HTML DOM Parser for PHP, and I am using the following markup:

$html = file_get_html(\'http://www.google.com\');

However h

相关标签:
1条回答
  • 2021-01-06 01:40

    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);
    

    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.

    0 讨论(0)
提交回复
热议问题