Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Javascript example of taking a webpage and performing text analysis

Options
  • 16-12-2008 9:53pm
    #1
    Registered Users Posts: 451 ✭✭


    Hi Folks,

    Is it possible for javascript to take "www.website.com/index.html" as a string, and then counting the number of times "apple" is in the webpage?

    Thanks,
    LK.


Comments

  • Closed Accounts Posts: 397 ✭✭galwayguy22


    I'm fairly sure you could use an Iframe for this.

    Set the src of the iframe to be the website you want to analyze, then use some regular expressions on the contents of the iframe.


  • Closed Accounts Posts: 397 ✭✭galwayguy22


    No, that doesn't seem to work. You don't have permission to read web pages not on your own domain
    <script>
    function show()
    {
     alert(document.getElementById('ifrm').contentWindow.document.body.innerHTML)
     
    }
    </script>
    <iframe width=600 height=600 frameborder=1 src="http://www.apple.com/" id=ifrm></iframe>
    <button onclick="show()" >Show HTML</button>
    

    Get this error in firefox:
    Error: Permission denied to get property Window.innerHTML
    Source File: file:///C:/Documents%20and%20Settings/MyActualName/Desktop/iframesample.html
    Line: 4


    You could always do it server side. I'm fairly sure, again, in PHP you can stream and read the contents of any url. Eg. file_get_contents


  • Registered Users Posts: 451 ✭✭LeperKing


    Ok, thanks for that. I won't have server side capabilities for this. Thanks for checking....

    LK.


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    You could use an AJAX request to read in the contents of a remote page and then do your calculations. Will still be client side.


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    I'm fairly sure, again, in PHP you can stream and read the contents of any url. Eg. file_get_contents

    Be aware that PHP5 switched this off by default for security reasons. Some hosts might have re-enabled it, but it's off by default.


  • Advertisement
  • Subscribers Posts: 9,716 ✭✭✭CuLT


    Could also do it with a simple enough bit of java, if you want to run it from your home computer or server or wherever.

    Starting point: :)
    import javax.swing.text.html.*;
    import javax.swing.text.*;
    import java.net.*;
    import java.io.*;
    import java.util.*;
    


Advertisement