0

I need to get some data from a Website (the user will change). However there is no 'good' API for Overwatch Stats. Is it possible in Javascript (Using Node.js) to get this data by the HTML tags or of sort?

For example, this is one of the lines in the source code:

<span class="summary-hero-name">McCree</span>

And the 3 hero's on display on the page each have the class summary-hero-name, is there any way to reference this data?

3 Answers3

1

So I figured this out, should have done a bit more research. I completed this by using a Node Package called scrape-it.

<scrape-it>("https://masteroverwatch.com/profile/pc/us/calvin-1337", {
  title: "span.summary-hero-name"
}).then(page => {
  console.log(page); // {title: 'McreeWidowmakerBastion' }
});
0

I believe this post will be helpful. I thought to use AJAX to make a request like this:...

<html>
<head>
<script type="text/javascript">
function go(){

var xhr = new XMLHttpRequest();

xhr.open("GET", "https://masteroverwatch.com/profile/pc/us/calvin-1337", false);
xhr.onreadystatechange = function(){

  if (xhr.readyState == 4) 
  {
    document.write(xhr.responseText);
  }
  else
  {
    document.write("nope");
  }
}

xhr.send();}

</script>
</head>
<body onload="go()">

</body>
</html>

Normally this would work if it was on the same domain, however, I got the error: "No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access". This is apparently a security feature. Seems like Cross-Origin Resource Sharing (CORS) is the way to go. Good luck.

Community
  • 1
  • 1
BrandonFlynn-NB
  • 384
  • 2
  • 14
0

You can use YQL for this (Yahoo query language). Click on the link below to see an example where i have used YQL and xpath to get a summary of the heroes as json. You can now parse this json to get stats for these heroes.

https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D'https%3A%2F%2Fmasteroverwatch.com%2Fprofile%2Fpc%2Fus%2Fcalvin-1337'%20and%20xpath%3D'%2F%2Fdiv%5B%40class%3D%22summary-list%22%5D%2Fdiv%5B%40class%3D%22summary-row-container%22%5D%2Fdiv%5B%40class%3D%22row%22%5D'&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=

Max08
  • 955
  • 1
  • 7
  • 16