Find text on website w/ applescript

Discussion in 'Mac Programming' started by zbotnik, Aug 10, 2010.

  1. zbotnik macrumors newbie

    Joined:
    Aug 10, 2010
    #1
    Hi all,

    I have an applescript that does what it's supposed to do. It first logs in to a website in one window, then after 3s delay performs another action in a new window. It works.

    Although, since loading times can vary, my script might be too fast (and yes, it needs to be as fast as possible). 3 second delays to wait for the page to load is normally enough, but sometimes it's not, in which case everything goes wrong. Using keystrokes, so they would end up in the wrong boxes and so on.

    I also don't want to wait for the whole page to load, since there are photos that can take forever, causing a real, unnecessary delay.

    Now, I'd like a piece of script that can look for the text "Xxxxxx" on the confirmation page that loads after this second action.
    If "Xxxxx" is not found, I'd like the script to be run again. If the text is in fact found, all is well.

    Using Safari.

    Grateful for any suggestions!
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    This is always my suggestion, because I don't know applescript very well, but would it be possible to do the heavy lifting as a shell script? I don't know how complex the transition between pages is, but it is likely possible to do what you need with curl. This also fixes the image loading issue, because curl is only going to grab the html of the page, so it should be much faster.

    If you post the URL(s) you're working with we might be able to help more.

    -Lee
     
  3. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #3
    A script that auto-logins then then grabs a confirmation code. Sounds like what some hackers use to automate account creation for spamming.

    Anyways, have the script disable images in Safari so it doesn't have to wait for them to download. Then the script can also check if the page is done downloading rather than waiting a specific amount of time.
     
  4. mrbash macrumors 6502

    Joined:
    Aug 10, 2008
    #4
    If you know the log-in information beforehand, you do not need to wait for the page to load. Why not directly send the POST/GET request to login?

    Store the login form's action parameters, and construct a URL with the appropriate attributes. I'm assuming that there is no client side processing that occurs on the login page and that there is no server token you have to pass along with the request.
     
  5. zbotnik thread starter macrumors newbie

    Joined:
    Aug 10, 2010
    #5
    Well, this is the login page: https://bokabostad.stockholm.se/LoggaIn.aspx

    I've tried to create the URL you mention, but unsuccessfully. Can I just look at the source code, or do I need to fetch something else?
     
  6. mrbash macrumors 6502

    Joined:
    Aug 10, 2008
    #6
    I saw the page and there may be some client side JS that transforms the input, also there were a few hidden input fields that seemed to have some generated values. I suspect that what I described will not work, although it is worth trying to construct a GET request with the parameters.

    Lee's suggestion of using curl is probably your best bet but the server may reject your login attempt if you don't maintain the same session.

    I was able to locate some AppleScript that loops till Safari has finished loading a page. You may want to try that instead. link to macosxhints.com
     

Share This Page