SHOW:
|
|
- or go back to the newest paste.
| 1 | public static void downloadItems(final String hrefParent, final String URL, final DownloadListener dl) | |
| 2 | - | {
|
| 2 | + | {
|
| 3 | - | new Thread(new Runnable() {
|
| 3 | + | new Thread(new Runnable() {
|
| 4 | - | @Override |
| 4 | + | @Override |
| 5 | - | public void run() {
|
| 5 | + | public void run() {
|
| 6 | - | Map<String, Object> result = new HashMap<String, Object>(); |
| 6 | + | Map<String, Object> result = new HashMap<String, Object>(); |
| 7 | - | JSONArray items = new JSONArray(); |
| 7 | + | JSONArray items = new JSONArray(); |
| 8 | - | JSONArray filters = new JSONArray(); |
| 8 | + | JSONArray filters = new JSONArray(); |
| 9 | - | dl.downloadStart(); |
| 9 | + | dl.downloadStart(); |
| 10 | - | String responseHTML = new Request(URL).execute(); |
| 10 | + | String responseHTML = new Request(URL).execute(); |
| 11 | - | Document doc = Jsoup.parse(responseHTML); |
| 11 | + | Document doc = Jsoup.parse(responseHTML); |
| 12 | - | Element priceListNode = doc.getElementsByClass("price_list").first();
|
| 12 | + | Element priceListNode = doc.getElementsByClass("price_list").first();
|
| 13 | - | if(priceListNode!=null) |
| 13 | + | if(priceListNode!=null) |
| 14 | - | for(Element priceTableNode : priceListNode.select(".mode_1"))
|
| 14 | + | for(Element priceTableNode : priceListNode.select(".mode_1"))
|
| 15 | - | for(Element priceTableTRNode : priceTableNode.select("tr"))
|
| 15 | + | for(Element priceTableTRNode : priceTableNode.select("tr"))
|
| 16 | {
| |
| 17 | - | String trClass = priceTableTRNode.attr("class");
|
| 17 | + | String trClass = priceTableTRNode.attr("class");
|
| 18 | - | String trPreview = priceTableTRNode.attr("preview");
|
| 18 | + | String trPreview = priceTableTRNode.attr("preview");
|
| 19 | - | if(trClass!=null && trClass.equals("section"))
|
| 19 | + | if(trClass!=null && trClass.equals("section"))
|
| 20 | - | {
|
| 20 | + | |
| 21 | - | try {
|
| 21 | + | try {
|
| 22 | - | JSONObject jsonObj = new JSONObject(); |
| 22 | + | JSONObject jsonObj = new JSONObject(); |
| 23 | - | Element sectionNameNode = priceTableTRNode.select(".t").first();
|
| 23 | + | Element sectionNameNode = priceTableTRNode.select(".t").first();
|
| 24 | - | String sectionName = sectionNameNode.text(); |
| 24 | + | String sectionName = sectionNameNode.text(); |
| 25 | - | jsonObj.put(Def.kItemHrefParent, hrefParent); |
| 25 | + | jsonObj.put(Def.kItemHrefParent, hrefParent); |
| 26 | - | jsonObj.put(Def.kItemsSectionName, sectionName); |
| 26 | + | jsonObj.put(Def.kItemsSectionName, sectionName); |
| 27 | - | jsonObj.put(Def.kItemsSectionItems, new JSONArray()); |
| 27 | + | jsonObj.put(Def.kItemsSectionItems, new JSONArray()); |
| 28 | - | items.put(jsonObj); |
| 28 | + | items.put(jsonObj); |
| 29 | - | } catch (Exception e) {
|
| 29 | + | } catch (Exception e) {
|
| 30 | - | Log.d("coccccccc", "exc sect: "+e.getLocalizedMessage());
|
| 30 | + | Log.d("coccccccc", "exc sect: "+e.getLocalizedMessage());
|
| 31 | - | } |
| 31 | + | |
| 32 | } | |
| 33 | - | else if(((trClass!=null && trClass.length()>0) && (trClass.equals("first") || trClass.equals("odd")))
|
| 33 | + | else if(((trClass!=null && trClass.length()>0) && (trClass.equals("first") || trClass.equals("odd")))
|
| 34 | - | || (trPreview!=null && trPreview.length()>0) |
| 34 | + | || (trPreview!=null && trPreview.length()>0) |
| 35 | - | || (priceTableTRNode.select(".c").first()!=null
|
| 35 | + | || (priceTableTRNode.select(".c").first()!=null
|
| 36 | - | && !priceTableTRNode.select(".c").first().text().equals("Код")) && items.length()>0)
|
| 36 | + | && !priceTableTRNode.select(".c").first().text().equals("Код")) && items.length()>0)
|
| 37 | - | {
|
| 37 | + | {
|
| 38 | - | //Код |
| 38 | + | //Код |
| 39 | - | Element codeNode = priceTableTRNode.select(".c").first();
|
| 39 | + | Element codeNode = priceTableTRNode.select(".c").first();
|
| 40 | - | String code = codeNode.text(); |
| 40 | + | String code = codeNode.text(); |
| 41 | - | //Комментарии |
| 41 | + | //Комментарии |
| 42 | - | Element commentsNode = priceTableTRNode.select(".co").first();
|
| 42 | + | Element commentsNode = priceTableTRNode.select(".co").first();
|
| 43 | - | String comments = commentsNode.text(); |
| 43 | + | String comments = commentsNode.text(); |
| 44 | - | //Рейтинг |
| 44 | + | //Рейтинг |
| 45 | - | String rating = "0"; |
| 45 | + | String rating = "0"; |
| 46 | - | Element ratingNode = priceTableTRNode.select(".r").first();
|
| 46 | + | Element ratingNode = priceTableTRNode.select(".r").first();
|
| 47 | - | Element ratingANode = ratingNode.select("a").first();
|
| 47 | + | Element ratingANode = ratingNode.select("a").first();
|
| 48 | - | if(ratingANode!=null) |
| 48 | + | if(ratingANode!=null) |
| 49 | - | {
|
| 49 | + | {
|
| 50 | - | String[] splitRating = ratingANode.attr("title").split("от");
|
| 50 | + | String[] splitRating = ratingANode.attr("title").split("от");
|
| 51 | - | if(splitRating.length>0) |
| 51 | + | if(splitRating.length>0) |
| 52 | - | rating = splitRating[0].trim().replace(",",".");
|
| 52 | + | rating = splitRating[0].trim().replace(",",".");
|
| 53 | - | } |
| 53 | + | } |
| 54 | - | //Название |
| 54 | + | //Название |
| 55 | - | Element nameNode = priceTableTRNode.select(".t").first();
|
| 55 | + | Element nameNode = priceTableTRNode.select(".t").first();
|
| 56 | - | String name = nameNode.text().replace("Помощь эксперта", "").trim();
|
| 56 | + | String name = nameNode.text().replace("Помощь эксперта", "").trim();
|
| 57 | - | //Картинка |
| 57 | + | //Картинка |
| 58 | - | String imageURL = (trPreview!=null)?trPreview:""; |
| 58 | + | String imageURL = (trPreview!=null)?trPreview:""; |
| 59 | - | //Цена |
| 59 | + | //Цена |
| 60 | - | Element priceNode = priceTableTRNode.select(".p").first();
|
| 60 | + | Element priceNode = priceTableTRNode.select(".p").first();
|
| 61 | - | String price = (priceNode!=null)?priceNode.text().replace(" ", "").trim():"";
|
| 61 | + | String price = (priceNode!=null)?priceNode.text().replace(" ", "").trim():"";
|
| 62 | - | for(Element priceDIVNode : priceNode.select("div"))
|
| 62 | + | for(Element priceDIVNode : priceNode.select("div"))
|
| 63 | - | if(priceDIVNode.attr("class")==null
|
| 63 | + | if(priceDIVNode.attr("class")==null
|
| 64 | - | || priceDIVNode.attr("class").length()==0
|
| 64 | + | || priceDIVNode.attr("class").length()==0
|
| 65 | - | || priceDIVNode.attr("class").equals("new"))
|
| 65 | + | || priceDIVNode.attr("class").equals("new"))
|
| 66 | - | price = (priceDIVNode!=null)?priceDIVNode.text().replace(" ", "").trim():"";
|
| 66 | + | price = (priceDIVNode!=null)?priceDIVNode.text().replace(" ", "").trim():"";
|
| 67 | - | try {
|
| 67 | + | try {
|
| 68 | - | JSONArray sectionItems = ((JSONObject)items.get(items.length()-1)).getJSONArray(Def.kItemsSectionItems); |
| 68 | + | JSONArray sectionItems = ((JSONObject)items.get(items.length()-1)).getJSONArray(Def.kItemsSectionItems); |
| 69 | - | JSONObject jsonObj = new JSONObject(); |
| 69 | + | JSONObject jsonObj = new JSONObject(); |
| 70 | - | jsonObj.put(Def.kItemHrefParent, hrefParent); |
| 70 | + | jsonObj.put(Def.kItemHrefParent, hrefParent); |
| 71 | - | jsonObj.put(Def.kItemCode, code); |
| 71 | + | jsonObj.put(Def.kItemCode, code); |
| 72 | - | jsonObj.put(Def.kItemComments, comments); |
| 72 | + | jsonObj.put(Def.kItemComments, comments); |
| 73 | - | jsonObj.put(Def.kItemGrade, rating); |
| 73 | + | jsonObj.put(Def.kItemGrade, rating); |
| 74 | - | jsonObj.put(Def.kItemName, name); |
| 74 | + | jsonObj.put(Def.kItemName, name); |
| 75 | - | jsonObj.put(Def.kItemImageURL, imageURL); |
| 75 | + | jsonObj.put(Def.kItemImageURL, imageURL); |
| 76 | - | jsonObj.put(Def.kItemPrice, price); |
| 76 | + | jsonObj.put(Def.kItemPrice, price); |
| 77 | - | sectionItems.put(jsonObj); |
| 77 | + | sectionItems.put(jsonObj); |
| 78 | - | } catch (Exception e) {
|
| 78 | + | } catch (Exception e) {
|
| 79 | - | Log.d("coccccccc", "exc item: "+e.getLocalizedMessage());
|
| 79 | + | Log.d("coccccccc", "exc item: "+e.getLocalizedMessage());
|
| 80 | - | } |
| 80 | + | } |
| 81 | - | } |
| 81 | + | } |
| 82 | } | |
| 83 | - | //TODO: заполнить фильтры |
| 83 | + | //TODO: заполнить фильтры |
| 84 | - | |
| 84 | + | |
| 85 | - | result.put(Def.kItemHrefParent, hrefParent); |
| 85 | + | result.put(Def.kItemHrefParent, hrefParent); |
| 86 | - | result.put(Def.kItemsURL, URL); |
| 86 | + | result.put(Def.kItemsURL, URL); |
| 87 | - | result.put(Def.kItems, items); |
| 87 | + | result.put(Def.kItems, items); |
| 88 | - | result.put(Def.kItemsFilters, filters); |
| 88 | + | result.put(Def.kItemsFilters, filters); |
| 89 | - | dl.downloadComplete(result); |
| 89 | + | dl.downloadComplete(result); |
| 90 | - | } |
| 90 | + | } |
| 91 | - | }).start(); |
| 91 | + | }).start(); |
| 92 | - | } |
| 92 | + | } |