-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
78 lines (51 loc) · 2.18 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner reader = new Scanner(System.in);
System.out.println("What would you like to cook today?");
String meal = reader.nextLine();
StringBuilder searchQuery = new StringBuilder();
final String[] split = meal.split(" ");
for (int i = 0; i < split.length; i++) {
if(i == split.length -1){
searchQuery.append(split[i]);
} else {
searchQuery.append(split[i]);
searchQuery.append("+");
}
}
Document searchResultsPage = Jsoup.connect("https://www.gutekueche.at/suche?s="+searchQuery.toString()).timeout(5000).get();
String recipeId = searchResultsPage.getElementsByTag("h3").first().getElementsByTag("a").first().attr("href");
System.out.println("\n");
Document doc = Jsoup.connect("https://www.gutekueche.at/"+recipeId).timeout(5000).get();
System.out.println(doc.title()+"\n");
Elements amounts = doc.getElementsByTag("tr");
StringBuilder recipe = new StringBuilder();
for(Element ele : amounts){
recipe.append(ele.getElementsByTag("td").first().attr("data-amount"));
recipe.append(" ");
recipe.append(ele.getElementsByTag("th").first().text());
recipe.append(" ");
recipe.append(ele.getElementsByTag("th").get(1).text());
recipe.append("\n");
}
Element instructions = doc.getElementsByClass("sec rezept-preperation").first();
Elements steps = instructions.getElementsByTag("li");
recipe.append("\n");
recipe.append("Zubereitung:\n\n");
int counter = 1;
for(Element ele : steps){
recipe.append(counter);
recipe.append(": ");
recipe.append(ele.text());
recipe.append("\n\n");
counter++;
}
System.out.println(recipe.toString());
}
}