Consult information from a website

Asked

Viewed 112 times

1

I require you to consult the website http://world.secondlife.com/resident/24e6998d-7bf2-4d03-b38b-acf8f2a21fc1 and take the value that is in meta name="member_count" content="53" in that case 53

Try to see if I can explain myself better.

I want to make a JS that manages to get the number of members of the link I posted up

So I intend that I can get that information and manipulate that value

The goal is to be able to display on my site the number of members of the group that shows on the link posted

What’s the best way to do this?

I’m trying to file a requisition XMLHttpRequest but I was unsuccessful

  function loadXMLDoc(){
    var xmlhttp; 
    if (window.XMLHttpRequest){
        xmlhttp=new XMLHttpRequest(); 
    }else{
        xmlhttp=new
        ActiveXObject("Microsoft.XMLHTTP"); 
    }

    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
            document.getElementById("myDiv").innerHTML=xmlhttp.responseText; 
        } 
    }

    xmlhttp.open("GET","http://world.secondlife.com/resident/24e6998d-7bf2-4d03-b38b-acf8f2a21fc1",true);

    xmlhttp.send(); 
}

<input type="button" onclick="loadXMLDoc()">Request data</button>
<div id="myDiv"></div>
  • Try to improve your question, I do not understand very well what you want to do.

  • Ever tried to use document.write() to make sure that he is retrieving the desired information?

  • has http://world.secondlife.com/resident/24e6998d-7bf2-4d03-b38b-acf8f2a21fc1 page and I would like to find a way to get the information 53 which is the number of members

  • does not return anything xmlhttp.responseText

  • 1

    You will not succeed. The server you are trying to access does not allow CORS. XMLHttpRequest cannot load http://world.secondlife.com/resident/24e6998d-7bf2-4d03-b38b-acf8f2a21fc1?_=1418733119899. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://jsbin.com' is therefore not allowed access.

  • There is no way for me to capture the information of the number of members ?

  • 1

    If the site does not allow CORS, then the only way will be by using a server-side approach, or by installing something in the client: browser extension or an HTTP server.

  • In LSL I made an llHTTPRequest() to the site http://world.secondlife.com/resident/24e6998d-7bf2-4d03-b38b-acf8f2a21fc1 and was able to obtain this information. The problem is that if I use LSL I have to send the information to a PHP and save it in a database. So I tried to use JS the same way I used LSL to get the same data. http://wiki.secondlife.com/wiki/World_API

Show 3 more comments

1 answer

1


CORS is a mechanism that allows a server’s resources to be accessed from a page in a domain other than the original domain. This happens to prevent just what you are trying to do and preserve server resources such as Bandwith and processing (which ultimately cost money).

Some sites enable CORS, for example, the API of stackoverflow and of github, but when this happens they usually always limit the amount of requests you can make, also to prevent abuse.

The website you are trying to get information does not allow CORS: XMLHttpRequest cannot load http://world.secondlife.com/resident/24e6998d-7bf2-4d03-b38b-acf8f2a21fc1?_=1418‌​733119899. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://jsbin.com' is therefore not allowed access.

This limitation is not imposed if you access SERVER-SERVER, as you found yourself.

The solution for you would be to implement on your server a proxy for communication with this site. Not necessarily you need to store this information in database.

READ ALSO:

1- Policy of the same origin
2- JSONP

  • how could I implement a proxy to solve the problem? But I finally understand why I can’t use Avascript because the site has defense and does not allow you to consult it.

  • This is specific to the programming language and the frameworks you are using in the backend, but in a generic way you need to do a requisicao ajax on your server, your server running PHP does a requisicao on the server of Second life, which returns the HTML of the page. Via PHP you do HTML Parsing and take the relevant information and then you return the ajax request to the browser, containing what you need. The implementation details of this I don’t know because I’ve never worked with php.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.