How do I pull out data of a page?

0 favourites
  • 14 posts
From the Asset Store
Template for making an interactive book or a simple story book
  • I want to develop an app, that shows you all the current prices of gas in Denmark because there aren't any.

    How do a load a string of data to my app from a website?

    Thank you.

  • You request the URL with AJAX, then wait for the response, then get the prices from AJAX.LastData. The task will be much easier if the page returns the data in XML or JSON format, otherwise you'll have to parse HTML and it's not pretty.

  • Thank you for the quick response.

    I cannot really make it seem to work. Could you give an elaborate explanation, or maybe a link to an article or video that shows this in-depth?

  • Here is a demo I made recently to get day of week from the internet:

    dropbox.com/s/pzhuot5i7779tn8/DOW_FromInternet.c3p

  • Ok, I see. How come that I can't pull data from this website: m.ingo.dk/cs/Satellite/m/JDK1/dk_DK/pg1334077745046/INGO/Priser.html

  • You can. But you'll get the entire page in HTML and will need to find the way to extract the prices from it.

  • There is no string in Ajax.LastData when I try for some reason though.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It works for me. Press F12 in preview and see is there are any error messages in the console log.

    Also, use this url:

    https://m.ingo.dk/cs/Satellite/m/JDK1/dk_DK/pg1334077745046/INGO/Priser.html

  • F12 tells me that there is "No 'Acces-Control-Allow-Origin'".

    And what's the difference between my URL, and the one you send me?

  • Tjums

    The access allow error is not your problem it is the owner of the websites they will have to enable cord. Do you own the website yourself?

    If so add the following to your .htaccess file:

    Header set Access-Control-Allow-Origin "*"

    Header set Access-Control-Allow-Headers "Content-Type"

    Header set Access-Control-Allow-Methods "GET"

  • I don't own the website, I just want the data from the website, and others, so that I can compare the prices of gas.

    So this means I am not able to get the data unless the owner allows me to?

  • I don't own the website, I just want the data from the website, and others, so that I can compare the prices of gas.

    So this means I am not able to get the data unless the owner allows me to?

    Tjums

    I think there is a way of spoofing the origin header, maybe try with submitting a header in the ajax request.

    take a look here:

    medium.com/netscape/hacking-it-out-when-cors-wont-let-you-be-great-35f6206cc646

    But

    dop2000 said it worked and is not getting a core error maybe you are submitting a wrong request.Tjums - have you used the site URL mentioned above?

  • I did use the URL mentioned above, yes.

  • First of, what you are trying to do is called "scraping".

    I don't think this is possible straight from C3, because no browser will allow a cross domain request if the server doesn't have the proper headers on the resource you are trying to fetch. Since you don't own the website you want to get the information from, you won't be able to set those headers.

    What you can do to get around this is to write a server side application which would not be bound to browser rules, make the request from that application and then have some endpoints on it which your client application can retrieve the information from. Since you will be in control of this server application, you will be able to set the 'Access-Control-Allow-Origin' on it.

    Of course the server application will not be made in C3. I will not go into detail on how to do any of this because it really isn't a C3 issue at this point.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)