Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

运行错误原因及解决办法 #6

Closed
idtolerate opened this issue Feb 7, 2018 · 1 comment
Closed

运行错误原因及解决办法 #6

idtolerate opened this issue Feb 7, 2018 · 1 comment

Comments

@idtolerate
Copy link

原因:微博的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();
}

保存后运行即可

@yAnXImIN
Copy link
Owner

yAnXImIN commented Mar 8, 2018

感谢,已经修改

@yAnXImIN yAnXImIN closed this as completed Mar 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants