Search a site [closed]

-1

Good afternoon .. I need to do a project in java on netbeans that the program go to the site and look for what was typed in the text field of the program. My theme is recipes and the site is cybercook, typing cake in the search screen of my program and clicking search, should open a new screen of my program with a list of the cakes that appear on the site. When you click on one of the cakes, you will have to open a new screen with some cake information. I do not know if it was clear what I need to do, I heard about the jsoup library to get things inside the site, but I could not use it for what I need, and I still have problems with button events and the text box . If anyone can help me, thank you.

FromwhatIunderstandofthecommentsIhavetodosomethinglikethis...IamindoubthowdoImakethetextthatistypedintothetextfieldbesavedinsomesortofsomethingvariable,sothatIcanthenputitinthepartofthecodewherethecakeiswritten.

    
asked by anonymous 31.03.2015 / 20:13

1 answer

2

The way you are doing, you are getting all the links (from the whole page). If your goal is to only get the revenue link, you need to inspect the HTML code to see where that information is loaded.

In the site in question, the recipes are loaded into a div with id resultado-busca . Inside it, each recipe is inserted into a div with class bloco-receita .

Still, there are many links , so you have to be more restricted. Well, within each div with class bloco-receita , there is a div with name foto-item and it's within that div that is the link that points to the recipe page.

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class BuscaReceitas {
    public static void main(String[] args) {
        Document pagina;
        try {
            pagina = Jsoup.connect("http://cybercook.com.br/resultado.php?ctr_busca=rapida&tp_busca_a=0&plv=bolo").get();

            Elements links = pagina.getElementById("resultado-busca")
                                   .getElementsByClass("bloco-receita");

            for(Element link : links.select(".foto-item > a")){
                System.out.println("Texto: " + link.attr("title"));
                System.out.println("Link: " + link.attr("href"));
            }
        } catch(Exception e){}
    }
}

I obtained the following test results:

... the list is extensive. : P

    
31.03.2015 / 21:02