[mobile] Download and parse/scrape web page

  • Hi all

    How would I go about downloading a web page's content for analysis/scraping/parsing, in a mobile context (Android/iOS).

    Thanks!

  • Use ajax to request the page, then you will have it in Ajax.LastData.

  • Use ajax to request the page, then you will have it in Ajax.LastData.

    Dang.. I've only used it to get project files. Thanks.

    edit: actually I don't seem to get anything in AJAX.LastData if I request a random web page. Does this work only if I target a specific file?

  • So what should I expect from this code?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Cant open the capx, I do not have the spritefont+ installed.

    But I imagine you have the ajax plugin doing a request or post and its not working.

    Hitting Ctrl shift J gives you the error console in chrome and FF.

    I forgot about the cross domain policies.

    Sites generally have cross domain security enabled. (origin access)

    So the ajax is not the best solution unless your trying to fetch info from one of your own sites on the same domain or sites having all origin access set to *

    You could use a hidden Iframe, load the page, and fetch the html from the frame with a bit of javascript.

  • Cant open the capx, I do not have the spritefont+ installed.

    But I imagine you have the ajax plugin doing a request or post and its not working.

    Hitting Ctrl shift J gives you the error console in chrome and FF.

    I forgot about the cross domain policies.

    Sites generally have cross domain security enabled. (origin access)

    So the ajax is not the best solution unless your trying to fetch info from one of your own sites on the same domain or sites having all origin access set to *

    You could use a hidden Iframe, load the page, and fetch the html from the frame with a bit of javascript.

    yeah sorry I use SF+ by default.

    Yes it's an Ajax request and Ajax.lastData comes up empty. You're right, I checked the Chrome console and it says "No 'Access-Control-Allow-Origin' header is present on the requested resource."

    Sorry to be clueless but could you give a bit more info on how I would go about the iFrame technique?

  • yeah sorry I use SF+ by default.

    Yes it's an Ajax request and Ajax.lastData comes up empty. You're right, I checked the Chrome console and it says "No 'Access-Control-Allow-Origin' header is present on the requested resource."

    Sorry to be clueless but could you give a bit more info on how I would go about the iFrame technique?

    Sorry to say, I just did some research on the cross site policies, and the methods used a couple years ago now also no longer seem to work.

    Well, some still work, in very old browsers :

    The current support for the adding of manual scripting in cs2 is rather limited.

    I added podes iframe plugin and did some tests, but did not succeed.

    There are some other approaches, such as using a webserver with php and having that request a webpage, which relays the results back to you. But its a messy solution.

    Outside of construct 2 its already a lot easier as you could add javascript to the iframe, and have the iframe send the innerHTML to the parent object (parent window). But in cs2 I can not add javascript or jquery to podes iframe. Perhaps you can ask Pode if it is possible to have it add it to the plugin so the iframe source is available in the iframes propperties in cs2.

    For various approaches you can google around for : javascript get iframe html

    I applied several of the suggestions by adding the browser object and podes iframe object.

    The iframe loaded a url, and with the browser object I executed various bits of javascript to get the innerHTML from the iframe to anything in cs2, and all that worked gives me the cross domain notifcation.

    document.getElementById('my_iframe').contentWindow.document.body.innerHTML;
    [/code:fpenqg7y]
  • I appreciate all your effort.. looks like I'm out of luck. I just wanted to grab some weather information and display the temperature :/ Do you know of any way to FTP a file into a C2 app?

  • Not really, I have not been using ftp options in cs2.

    Doesnt Rex have anything ?

    Perhaps the option to get project files ?, and externally placing a file in the app folder ?

  • I did scan the add-ons but I'll have another look. Thanks again

  • Hi codah

    you have anything? D:

    ineed grab information weather too

  • Hi codah

    you have anything? D:

    ineed grab information weather too

    no..

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