0

So this question I thought would be beyond simple. Yet after a solid hour of searching JavaScript and node js documentation and other questions on this site I've only found things that have to do with the same origin policy.

What I want is to make a simple request to a url and read it's html/source code. This is to query a wiki and return the top link from the search results. I can handle dealing with the html myself, but I am absolutely dumbfounded as to how to get the html. I know how to do it very easily with Lua socket in a single line, which is how I did this when making a twitch bot, but now that I am adapting it to discord I'm coding it in JavaScript, and I am not as well versed in JavaScript.

Does anybody know how to go about this?

My current code:

function SearchWiki(query) {
    console.log("I was called, I guess")
    var options = {
        path: encodeURI(query),
        method: "GET"
    }
    var request = http.request("http://pm-challenge.wikia.com/wiki/Special:Search?search=", options, function (res) {
        var data = '';
        res.on('data', function (chunk) {
            data += chunk;
        });
        res.on('end', function () {
            console.log(data);  
        });
    });
    request.on('error', function (e) {
        console.log(e.message);
    });
    request.end();
}
warspyking
  • 3,045
  • 4
  • 20
  • 37

0 Answers0