Seting User Agent param in PHP Simple HTML DOM Parser

后端 未结 2 1393
半阙折子戏
半阙折子戏 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:34

    Thanks Michal Čihař, you are right I just made some changes in the load_file() function of simple_html_dom class and it worked

    // load html from file
        function load_file() {
            $args = func_get_args();
            // Added by Mithun
            $opts = array(
                'http'=>array(
                    'method'=>"GET",
                    'header'=>"Accept-language: en\r\n" .
                    "User-Agent:    Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6\r\n".
                    "Cookie: foo=bar\r\n"
                )
            );
            $context = stream_context_create($opts);
            $args[1] = FALSE;
            $args[2] = $context;
            // End Mithun
            $this->load(call_user_func_array('file_get_contents', $args), true);
        }
    

提交回复
热议问题