当前位置: 代码迷 >> Java Web开发 >> 求教关于 HttpClient 抓取页面回来403,请大神赐教啊
  详细解决方案

求教关于 HttpClient 抓取页面回来403,请大神赐教啊

热度:763   发布时间:2016-04-16 22:12:46.0
求教关于 HttpClient 抓取页面返回403,请大神赐教啊!

        HttpClient httpClient = new HttpClient();
        GetMethod getMethod = new GetMethod(url);
        try
        {
            int result = httpClient.executeMethod(getMethod);
            System.out.println(result);
        }
        catch (HttpException e)
        {
            e.printStackTrace();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        finally
        {
            if (getMethod != null)
            {
                getMethod.releaseConnection();
            }
        }


在抓取http://www.giveyousomecolortoseesee.com  给你些颜色看看 搜索页面的时候会返回403。
例如url 值为http://www.giveyousomecolortoseesee.com/search_2_dnf.htm 即搜索的关键词是dnf(使用代码抓取前未使用浏览器使用dnf该关键词进行检索),返回的结果为403。如果之前使用浏览器对dnf关键词进行过检索则能够拿到正确的返回值200,由于刚接触这块的内容 比较迷惑 所以发出来求教,不胜感激
------解决方案--------------------
你可以去看看这个,上面有一些伪装浏览器Header的代码  可以试试  成功了给分哦  
  相关解决方案