Search on a website

Asked

Viewed 446 times

-1

Good afternoon.. I need to do a java project in netbeans that the program goes to the site and searches for what was typed in the program’s text field. My theme is recipes and the site is cybercook, typing cake on 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 don’t know if it was clear what I need to do, I heard about the jsoup library to get things inside the site, but I couldn’t 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. inserir a descrição da imagem aqui

From what I understand of the comments I have to do something like this... I’m doubtful how I do for the text that is typed in the text field to be saved in some variable something of the kind, so I can then put it in the code part where this written cake.

inserir a descrição da imagem aqui

  • 1

    Welcome to Stackoverflow friend, this is a software request and not a real problem, so it is characterized as off-topic, as it is not a problem that can be reproduced to my view. What have you tried?

  • 1

    Ola Gabriel, welcome to [pt.so]. The community is focused on objective questions about programming and yours is very broad. We can help you with specific problems, but we can’t do everything for you. Bring your specific questions along with the details of the effort you have already made to resolve them and the community will support you. Also recommend a visit to [help] and [Ask], and also q make the [tour]

  • I edited the port to try to translate one of my doubts

  • 1

    Images do not help in much Gabriel, has to post an example that can be reproduced. LEIA: http://answall.com/help/mcve. and then edit your question. : ) good luck

1 answer

2


The way you’re doing it you’re getting all the links (from the whole page). If your goal is to get only the recipe link, you need to inspect the HTML code to verify where this information is loaded.

On the site in question, 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, then you need to be more strict.
Well, inside every classy div bloco-receita, there’s a div with a name foto-item and it is within that div that is the link which 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 got the following test results:

output

... the list is extensive. :P

Browser other questions tagged

You are not signed in. Login or sign up in order to post.