java - How to find all anchors matching a word with Jsoup? -


thank in advance time. code supposed connect website, , scrape os model line has word inputted user. search word, go line, , scrape os attribute on line word. don't see why code not working, , appreciate please.

here website http://www.tabletpccomparison.net/

here code:

import java.io.ioexception; import java.util.iterator; import java.util.scanner;  import org.jsoup.jsoup; import org.jsoup.nodes.document; import org.jsoup.nodes.element; import org.jsoup.select.elements;  public class extrapart1 { public static void main(string args[]) throws ioexception{     scanner input = new scanner(system.in);     string word = "";     system.out.println("type in trying search for.");     word = input.nextline();     system.out.println("this program find quality website it");     string url = "http://www.tabletpccomparison.net/";     document doc = jsoup.connect(url).get();     elements elements = doc.select("a");     for(element e : elements){         if(e.equals(word)){             string next_word = e.getelementsbyclass("tablejx2ope_sis").text();             system.out.print(next_word);         }     }  } } 

the problem lies here:

if(e.equals(word)){         string next_word = e.getelementsbyclass("tablejx2ope_sis").text();         system.out.print(next_word); } 

e element , compared string. try instead:

if(e.text().equals(word)) {    // ... } 

you may simplify loop this:

string cssquery = string.format("a:containsown(%s)", word); elements elements = doc.select(cssquery);  for(element e : elements){     string nextword = e.getelementsbyclass("tablejx2ope_sis").text();     system.out.print(nextword); } 

references


Comments