Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Java by nutrolshok ( 7 years ago )
package net.nutrolshok.ParseBKMenu;

import java.io.IOException;

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

public class Main {
	
	private static String[] categoriesm;
	private static String[] links;

	public static void main(String[] args) {
		try {
			String URL = "https://burgerking.ru/menu";
			parseMenu(URL);
			Window w = new Window();
			w.setVisible(true);
		} catch(IOException unused) {
			print("Error: IOException");
		}
	}
	
	private static void parseMenu(String URL) throws IOException {
		Document html = Jsoup.connect(URL).get();
        print(html.title());
        Elements categories = html.select(".food-category a");
        categoriesm = new String[categories.size()];
        links = new String[categories.size()];
        int current = 0;
        for(Element category: categories) {
            String title = category.text();
            String link = category.absUrl("href");
            print(title + " - " + link);
            categoriesm[current] = title;
            links[current] = link;
            current++;
        }
	}
	
	public static String[] parseCategory(int index) throws IOException {
		Document html = Jsoup.connect(links[index]).get();
		Elements items = html.select(".food-item span");
		String[] ans = new String[items.size()];
		int current = 0;
		for(Element item : items) {
			String title = item.text();
			print("\t" + title);
			ans[current] = title;
			current++;
		}
		return ans;
	}
	
	public static void print(String string) {
		System.out.println(string);
	}
	
	public static String[] getCategories() {
		return categoriesm;
	}

}

 

Revise this Paste

Your Name: Code Language: