0

I am trying to fetch text from other site I am trying to scrape the text from the site using https://multiverso.me/AllOrigins.

This site get all the content of page in string format. For example I am trying to get data from URL: TOI link. I am using this code:

 $.getJSON('http://allorigins.me/get?url=https%3A//timesofindia.indiatimes.com/sports/asian-games/such-a-long-walk-from-living-in-cowshed-to-asiad-medallist/articleshow/65361646.cms&callback=?', function(data){
console.log(data);
});

The return value is:

 {contents: "<!DOCTYPE HTML><html xmlns:xslthelper="com.times.u…deoSwitch" type="hidden" value="1"></body></html>", status: {…}}

It is giving me the result as a string. But I want just text. I've tried the following:

  $.getJSON('http://allorigins.me/get?url=https%3A//timesofindia.indiatimes.com/sports/asian-games/such-a-long-walk-from-living-in-cowshed-to-asiad-medallist/articleshow/65361646.cms&callback=?', function(data){
  // $('#output').html(data.contents);
console.log(data);
var str = data.contents;
html = $.parseHTML(str)
console.log($(html).find('h2').text());

});

This is returning only one h2 tag but I want to fetch all text on the site.

When I am using the body tag I am getting nothing returned. In this question jQuery get the text of all elements in a page

I can see accepted answer is saying I should use:

 $('body').text()

Is there any way I can fetch all text from a site, just text not javascript or anything else.

For example have a look at this : Demo Of fetching text from site

In this demo you can see when I paste the url I can get all text

0 Answers0