Best way to get definitions from google?

I am trying to create a simple function where the user can specify a term and the program gets the definition for it and returns it. The best definition system I know is the Google keyword “define” in search queries, where if you start a query with “define” or “define:” etc., it returns very accurate and sufficient definitions. However, I have no idea how to access this information programmatically.

The new Google search engine API does not show definitions, and the old one gives slightly better results, but is outdated and still does not show the same definitions that I see when I use this term in a browser.

Google Failure, I turned to Wikipedia, which has a huge API, but I still could not find a way to extract resumes such as Google definitions.

So my question is: does anyone know how I can get this information from Google via the API or in any other way?

This is an old question , but asks the same thing. Except that the answers above are no longer applicable as the Google dictionary no longer exists.

Update: So now I'm going down the road trying to clear the definitions right from the page itself . Now the problem is that when I visit the page in the browser (Firefox), the definitions appear, but when I clear them using cheerio , they do not appear anywhere on the page. I should mention that I am scraping the page through nitrous.io so that it displays the page from a different region and operating system into that one, m viewing it in a browser, so that maybe it is associated with the region. Let's look further.

Update 2.0: I think that perhaps the definitions are loaded asynchronously, so I have no idea how to clean them, because I have never done a scraper before, and I'm just a beginner :(

3.0: , , , . Firefox, :

enter image description here

, IE (8), :

enter image description here

- ?

+4
1

- . . :

var request = require('request')
  , cheerio = require('cheerio');

var searchTerm = 'test';

request({url:'https://www.google.co.uk/search?q=define+'+searchTerm,headers:{"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0"}}, function(err, resp, body){
  $ = cheerio.load(body);
    var defineBlocks = $(".lr_dct_sf_sen");
    var numOfBlocks = (defineBlocks.length < 3) ? defineBlocks.length : 3;
    for (var i=0; i<numOfBlocks; i++){
        var block = defineBlocks[i].children[1].children[0]; //font-size:small level
        process(block);

        function process (block) {
            for (var i=0; i<block.children.length; i++){
                var line = block.children[i];
                if ("style" in line.attribs){ // main text
                    exampleStr = "";
                    for (var k=0; k<line.children.length; k++){
                        exampleStr += line.children[k].children[0].data;
                    }
                    console.log(exampleStr);
                } else if ("class" in line.attribs){ // example
                    console.log("\""+line.children[1].children[0].data+"\"");
                } else { // nothing i want

                }
            }
        }
    }
});
+2

Source: https://habr.com/ru/post/1532126/


All Articles