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,由于刚接触这块的内容 比较迷惑 所以发出来求教,不胜感激
HttpClient 搜索 URL Java
------解决方案--------------------
你可以去看看这个,上面有一些伪装浏览器Header的代码 可以试试 成功了给分哦
