how to read info from the web? and I need to look for words specific.

edited December 2017 in Questions about Code

hi. how to read info from the web? and I need to look for words specific.

 String[] allwords;

// Any punctuation is used as a delimiter.
String delimiters = "";
String word ="mercado";

void setup() {
  size(360, 640);

  // Load A Midsummer Night's Dream into an array of strings
  String url = "https://articulo.mercadolibre.com.ar/MLA-696187159-split-samsung-3000-fg-frio-calor-modelo-inverter-ar12ksw-_JM";
  String[] rawtext = loadStrings(url);

for (int i = 0; i<rawtext.length; i++) {

  String ss = rawtext[i];


  if(word==ss){

    println("OK");
    }

}

the problem, it's like the data is encoded, and it does not show all the information on the wed. like there are windows to see the information of a page. I do not understand.

Tagged:

Answers

  • edited December 2017

    `

    Here it works but I do not see some words. for example sold "vendidos", nor its value

        String[] allwords;
        // Any punctuation is used as a delimiter.
        String delimiters = " ><.,/(){}!&#=;_-:?[]|'";
        //String delimiters = "";
        String word[] ={ "vendidos","Samsung","3000","Fg","Frio","Calor","Modelo","Inverter","Ar12ksw"};
    
        void setup() {
          size(360, 640);
    
          // Load A Midsummer Night's Dream into an array of strings
          String url = "https://articulo.mercadolibre.com.ar/MLA-691839284-laser-35-watts-blue-laser-con-modulacion-ttl-_JM";
          String[] rawtext = loadStrings(url);
           String everything = join(rawtext, " " );
           allwords = splitTokens(everything, delimiters);  
    
        for (int i = 0; i<allwords.length; i++) {
    
          String ss = allwords[i];
         // println(ss);
    
          if (ss.equals(word[0]       )) {
            //println(ss);
            println("OK");
            }
    
        }
    `
    
  • Parsing HTML for content can be extremely hard, and it is often better to use an existing HTML parsing library rather than write your own.

    Are you trying to work only with only specific pages, or deal with potentially any URL?

    Are the URLs going to be yours -- do you control the content?

    Rather than equals, you probably want to find strings in other strings -- otherwise the way that the delimiters split the tokens will often prevent you from making matches.

Sign In or Register to comment.