We need to take the photo from national geographic photo of the day for an android project. We are using jsoup to do it and it is working for other sites and photos we tried to get, but not with this one. http://www.nationalgeographic.com/photography/photo-of-the-day
This is the link to the photo that we need to get. If you inspect the page, you will see that the element which contains the link, has multiple links of the photo in different sizes. So we suspect that this is the problem. Here is the element with all the links:
<source srcset="http://yourshot.nationalgeographic.com/u/fQYSUbVfts-T7odkrFJckdiFeHvab0GWOfzhj7tYdC0uglagsDq-TNIRQ3qELJppd8ZLNRvnhakVub3VQlC2V5_yAGtyNoIAtaUObf5sBn_PGVEIlVVcerfj6l1ovYy2W4h7lMAkEVLdiCZKr9S9wuwge1myLnbvmEvxjeQ-HOfdmgprhGjqn4pNtAwmKvwU6FOW3O0jR-t4LlattRw52wBmvg/ 240w, http://yourshot.nationalgeographic.com/u/fQYSUbVfts-T7odkrFJckdiFeHvab0GWOfzhj7tYdC0uglagsDq-TNIRQ3qELJppd8ZLNRvnhakVub3VQlC2V5_yAGtyNoIAtaUObf5sBn_PGVEIlVVcerfj6l1ovYy2W4h7lMAkEVLdiCZKr9S9wuwge1myLnbvmEvxjeQ-HOfdmgprhGjqn4pNtAwmKvwU6cKxp_v-TRYywK8kMonNsWFMiA/ 320w, http://yourshot.nationalgeographic.com/u/fQYSUbVfts-T7odkrFJckdiFeHvab0GWOfzhj7tYdC0uglagsDq-TNIRQ3qELJppd8ZLNRvnhakVub3VQlC2V5_yAGtyNoIAtaUObf5sBn_PGVEIlVVcerfj6l1ovYy2W4h7lMAkEVLdiCZKr9S9wuwge1myLnbvmEvxjeQ-HOfdmgprhGjqn4pNtAwmKvwU76IwFM89MgsU2CsVpABa94yrwg/ 500w, http://yourshot.nationalgeographic.com/u/fQYSUbVfts-T7odkrFJckdiFeHvab0GWOfzhj7tYdC0uglagsDq-TNIRQ3qELJppd8ZLNRvnhakVub3VQlC2V5_yAGtyNoIAtaUObf5sBn_PGVEIlVVcerfj6l1ovYy2W4h7lMAkEVLdiCZKr9S9wuwge1myLnbvmEvxjeQ-HOfdmgprhGjqn4pNtAwmKvwU7Lx-mjq8_Dk9iI7H4kcoPo-SmA/ 640w, http://yourshot.nationalgeographic.com/u/fQYSUbVfts-T7odkrFJckdiFeHvab0GWOfzhj7tYdC0uglagsDq-TNIRQ3qELJppd8ZLNRvnhakVub3VQlC2V5_yAGtyNoIAtaUObf5sBn_PGVEIlVVcerfj6l1ovYy2W4h7lMAkEVLdiCZKr9S9wuwge1myLnbvmEvxjeQ-HOfdmgprhGjqn4pNtAwmKvwU4kJMUl3WmTvlAFqfo4wIlDssvw/ 800w, http://yourshot.nationalgeographic.com/u/fQYSUbVfts-T7odkrFJckdiFeHvab0GWOfzhj7tYdC0uglagsDq-TNIRQ3qELJppd8ZLNRvnhakVub3VQlC2V5_yAGtyNoIAtaUObf5sBn_PGVEIlVVcerfj6l1ovYy2W4h7lMAkEVLdiCZKr9S9wuwge1myLnbvmEvxjeQ-HOfdmgprhGjqn4pNtAwmKvwU6-HA9n31rVvmbG5touqPt59wY3s/ 1024w, http://yourshot.nationalgeographic.com/u/fQYSUbVfts-T7odkrFJckdiFeHvab0GWOfzhj7tYdC0uglagsDq-TNIRQ3qELJppd8ZLNRvnhakVub3VQlC2V5_yAGtyNoIAtaUObf5sBn_PGVEIlVVcerfj6l1ovYy2W4h7lMAkEVLdiCZKr9S9wuwge1myLnbvmEvxjeQ-HOfdmgprhGjqn4pNtAwmKvwU6-dIS7lLTB0CSOM4O0wlvLx9pDnb/ 1600w, http://yourshot.nationalgeographic.com/u/fQYSUbVfts-T7odkrFJckdiFeHvab0GWOfzhj7tYdC0uglagsDq-TNIRQ3qELJppd8ZLNRvnhakVub3VQlC2V5_yAGtyNoIAtaUObf5sBn_PGVEIlVVcerfj6l1ovYy2W4h7lMAkEVLdiCZKr9S9wuwge1myLnbvmEvxjeQ-HOfdmgprhGjqn4pNtAwmKvwU6FcgiBNz-Nj7_J7e61F6_8oUXwoV/ 2048w" sizes="730px" data-reactid=".5.0.1.0.0.$http=2//www=1nationalgeographic=1com/photography/photo-of-the-day/2017/01/boy-buffalo-thailand.0.0.0.0.0.0.0.0">
As you can see, there are multiple links, so we also tried to split the code and get just one of them, but jsoup doesn't seem to get any of the code in the first place. Here is the code:
Document doc = Jsoup.connect("http://www.nationalgeographic.com/photography/photo-of-the-day").get();
Elements img = doc.select("div.modules-images__placeholder source[srcset]");
imgSrc = img.attr("srcset"); //srcset
String[] splitStr = imgSrc.split("\\s+");
int n = splitStr.length;
imgSrc = splitStr[n-2];
//Download Image from URL
InputStream input = new java.net.URL(imgSrc).openStream();
//Decode Bitmap
bitmap = BitmapFactory.decodeStream(input);
myWallpaperManager.setBitmap(bitmap);