yAnXImIN / weiboPicDownloader

免登录下载微博图片 爬虫 Download Weibo Images without Logging-in

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

运行错误原因及解决办法

idtolerate opened this issue · comments

原因:微博的json格式改了
解决办法 在WeiboUtils类中的getImgURL方法改成:
private static int getImgURL(String containerid,int page, List urls) throws ParseException, IOException{
String url = "https://m.weibo.cn/api/container/getIndex?count=25&page="+page+"&containerid="+containerid;
HttpClient httpClient = getHttpClient();
HttpGet get = new HttpGet(url);
get.setHeader("User-Agent", USER_AGENT);
HttpResponse response = httpClient.execute(get);
String ret = EntityUtils.toString(response.getEntity(), "utf-8");
JsonObject root = new JsonParser().parse(ret).getAsJsonObject();
JsonObject asJsonObject = root.getAsJsonObject("data");
JsonArray array = asJsonObject.getAsJsonArray("cards");
System.out.println(array);
for(int i=0;i<array.size();i++){
JsonObject mblog = array.get(i).getAsJsonObject().getAsJsonObject("mblog");
if(mblog!=null){
JsonArray pics = mblog.getAsJsonArray("pics");
if(pics!=null){
for(int j=0;j<pics.size();j++){
JsonObject o = pics.get(j).getAsJsonObject();
JsonObject large = o.getAsJsonObject("large");
if(large!=null){
urls.add(large.get("url").getAsString());
}
}
}
}
}
return array.size();
}

保存后运行即可

感谢,已经修改