So i have function that is called when i click a button , it goes as below
var min_news_id = "68feb985-1d08-4f5d-8855-cb35ae6c3e93-1";
function loadMoreNews(){
$("#load-more-btn").hide();
$("#load-more-gif").show();
$.post("/en/ajax/more_news",{'category':'','news_offset':min_news_id},function(data){
data = JSON.parse(data);
min_news_id = data.min_news_id||min_news_id;
$(".card-stack").append(data.html);
})
.fail(function(){alert("Error : unable to load more news");})
.always(function(){$("#load-more-btn").show();$("#load-more-gif").hide();});
}
jQuery.scrollDepth();
Now i don't have much experience with javascript , but i assume its returning some json data from some sort of api at "en/ajax/more_news" .
Is there i way could directly call this api and get the json data from my python script. If Yes,how?
If not how do i scrape the content that is being generated?
urllib2to retrieve the data from the API, andjson.loadsto parse the JSON into a Python dictionary.r = requests.post('http://inshorts.com/en/ajax/more_news', json={'category':'','news_offset':min_news_id})json.loads(r)to parse the JSON response, andr['html']will contain the HTML from the response.import json import requests min_news_id="68feb985-1d08-4f5d-8855-cb35ae6c3e93-1" r = requests.post('http://inshorts.com/en/ajax/more_news', json={'category':'','news_offset':min_news_id}) print (r.url)data=, notjson=.