use data from external webpage to display response

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • davedmd
    New Member
    • Aug 2008
    • 2

    use data from external webpage to display response

    Does anyone know how you can possibly read an external webpage or search it for an exact expression or image. If it exists return an alertbox "found, otherwise "not found"
    Javascript would be great. I found this example but cant seem to make it work.

    URL url = new URL("http://factfinder.cens us.gov/home/saff/main.html?_lang =en");
    HttpURLConnecti on conn = (HttpURLConnect ion) url.openConnect ion();
    BufferedReader rd = new BufferedReader( new InputStreamRead er(conn.getInpu tStreamReader() );

    String line;
    while(line=rd.r eadLine() != null) {
    response += line;
    }
    if (line == "2006 County Business Patterns"){
    alert ('found');
    }else{
    alert ('not found');
    }
    </script>

    any examples or help would be appreciated...
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    You are not mixing Java and Javascript are you?

    Comment

    • Nepomuk
      Recognized Expert Specialist
      • Aug 2007
      • 3111

      #3
      Originally posted by r035198x
      You are not mixing Java and Javascript are you?
      The code certainly looks like Java, so I suspect the OP just made a mistake calling it JavaScript.
      Just in case, here's what they are: JavaScript and Java

      To answer the OP's question, your error is in the line[code=java]if (line == "2006 County Business Patterns"){...[/code]You don't compare Strings like that. Use this instead:[code=java]if (line.equals("2 006 County Business Patterns")){...[/code]
      Greetings,
      Nepomuk

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        There are a couple of errors in there:

        1) that code is Java (except for that 'alert()' method?)
        2) you compare Strings using its equals() method, not by using ==
        3) your code only checks the last line
        4) appending Strings like that is highly inefficient; use a StringBuilder.

        kind regards,

        Jos

        Comment

        • davedmd
          New Member
          • Aug 2008
          • 2

          #5
          This stuff is too complicated. I was hoping there was a simple javascript one could build to look up data, but java, javascript... just too much to deal with.
          maybe someone one day will figure out a simple web page look up script
          thanks for the help........... .....

          Comment

          Working...