Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- static Map<String, Integer> list = new HashMap();
- static Map<String, Integer> results = new HashMap();
- static BasicCookieStore cookieStore = new org.apache.http.impl.client.BasicCookieStore();
- public static void main(String[] args) throws UnirestException, IOException {
- HttpClient client = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
- Unirest.setHttpClient(client);
- addItem("000.891.63",1);
- addItem("001.301.29",1);
- addItem("001.301.67",1);
- int itemsCount = 0;
- for (Map.Entry<String, Integer> item : list.entrySet()) {
- HttpResponse response = send(item.getKey(), item.getValue());
- results.put(item.getKey(), response.getStatus());
- System.out.println(item + " \t " + response.getStatus());
- itemsCount += item.getValue();
- }
- System.out.println("Items count: " + itemsCount);
- System.out.println("List size: " + list.size());
- }
- public static void addItem(String number, Integer count) {
- if(count == 0) return;
- if (list.containsKey(number)) {
- list.put(number, list.get(number) + count);
- return;
- }
- list.put(number, count);
- }
- public static String parse(String number, int count) throws IOException {
- String location = "http://www.ikea.com/ru/ru/catalog/products/" + number.replace(".", "") + "/";
- Connection connection = Jsoup.connect(location);
- connection.request().ignoreHttpErrors(true);
- Document doc = connection.get();
- if (doc.location().equals(location) && doc.getElementsByClass("errorHead").isEmpty()) {
- String name = doc.getElementById("name").text();
- String type = doc.getElementById("type").text();
- String price = doc.getElementById("price1").text().replace(".–", "");
- Element ifPrice = doc.getElementById("price5");
- if(ifPrice != null && ifPrice.hasText()) price = ifPrice.text().replace(".–", "");
- System.out.println(number + "\t" + name + " " + type + "\t" + price.replace(" ", "").replace(" ", "") + "\t" + count);
- } else if (!number.contains("S")) {
- parse("S" + number, count);
- } else {
- System.out.println(number + "\tНе найден");
- }
- return "";
- }
- public static HttpResponse send(String number, Integer count) throws UnirestException {
- HttpResponse response = Unirest.post("http://www.ikea.com/webapp/wcs/stores/servlet/IrwInterestItemAddByPartNumber")
- .header("content-type", "application/x-www-form-urlencoded")
- .field("quantity", count, "application/x-www-form-urlencoded")
- .field("partNumber", number, "application/x-www-form-urlencoded")
- .field("listId", "", "application/x-www-form-urlencoded")
- .asString();
- return response;
- }
- public static void login() throws UnirestException {
- String user = "";
- String password = "";
- Unirest.post("https://secure.ikea.com/webapp/wcs/stores/servlet/Logon")
- .header("content-type", "application/x-www-form-urlencoded")
- .field("logonId", user)
- .field("logonPassword", password)
- .field("storeId", 23)
- .asString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement