0

I want my Discord Bot to be able to visit a website and read its source code so that it can search for specific fields and store their info to variables and eventually relay that information to the room.

<tr id="troop_6170" class="troop-row" data-id="6170" data-name="Abynissia">

In the sample above, it would search for "data-name" and store "Abynissia" in a variable, along with other information, but only one example is necessary.

I have found a few sites that have explained how to at least start, but when I test the bot, it's not recognizing

var ws = new XMLHttpRequest();

It returns an error that XMLHttpRequest is not defined. None of the sites where I found this information explain whether or not there's something else that I'm supposed to have installed, nor do they show any previous code that might explain how to define XMLHttpRequest()

Thank you.

Michael Luna
  • 1
  • 1
  • 1
  • I haven't used it, but I think `XMLHttpRequest()` is used in frontend JS, not Node. You could try using the [xmlhttprequest](https://www.npmjs.com/package/xmlhttprequest) NPM package, although there might be a way to use Http instead – RSchneyer Jun 18 '19 at 23:13
  • I apologize for my ignorance. I only know what I've read and I've had a very tiring time trying to find anything with just a basic example of how to simply access and read source code. I honestly thought it would be a rather simple process. As far as the string manipulation after reading it, that's easy as pie. My main issue is just getting the code to go to website.com and read the source. – Michael Luna Jun 18 '19 at 23:21
  • That's alright, it's a learning experience for me too. [This](https://stackoverflow.com/questions/5801453/in-node-js-express-how-do-i-download-a-page-and-gets-its-html) post might be a good starting off point for using Http – RSchneyer Jun 18 '19 at 23:25
  • I believe you may have shown me what I've been looking for. I searched stackoverflow for at least an hour and you found it in seconds. I'm amazed at your quick findings... and slightly embarrassed. – Michael Luna Jun 18 '19 at 23:31
  • Thanks! Good luck with the rest of your project! – RSchneyer Jun 18 '19 at 23:49

0 Answers0