Seting User Agent param in PHP Simple HTML DOM Parser

后端 未结 2 1390
半阙折子戏
半阙折子戏 2021-02-02 04:53

Is there any way to include the user agent string along with the request send by PHP Simple HTML DOM Parser?

2条回答
  •  盖世英雄少女心
    2021-02-02 05:16

    By looking at the code it should be possible by using context streams, something like:

    $context = stream_context_create();
    stream_context_set_params($context, array('user_agent' => 'UserAgent/1.0'));
    file_get_html('http://www.google.com/', 0, $context);
    

    Alternatively you can also set default value in php.ini.

提交回复
热议问题