Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Javascript example of taking a webpage and performing text analysis

  • 16-12-2008 09:53PM
    #1
    Registered Users, Registered Users 2 Posts: 452 ✭✭


    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, Registered Users 2 Posts: 452 ✭✭LeperKing


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

    LK.


  • Registered Users, Registered Users 2 Posts: 21,278 ✭✭✭✭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