Exemplo n.º 1
0
 public static boolean getFormFields(
     ResponseWrapper rw, List<NameValuePairString> hiddenFormFields, String formSelector) {
   // --- analisi della pagina contente la form, specifica al sito
   Document doc = rw.getJSoupDocument();
   Elements els = doc.select(formSelector); // per debug, dovrebbe essere uo
   if (els == null || els.size() <= 0) {
     log.error("unable to find form at selector: " + formSelector);
     System.exit(1);
     return false;
   }
   Element loginForm = els.get(0);
   if (loginForm == null) {
     log.error("failed to get form to analyze at: " + rw.dump());
     System.exit(1);
   }
   // log.info("login form OUTER HTML\n" + loginForm.outerHtml());
   Elements inputFields = loginForm.select("input");
   // display all
   for (Element e : inputFields) {
     String type = e.attr("type");
     if (type.equals("submit")) {
       continue;
     }
     String attrName = e.attr("name");
     hiddenFormFields.add(new NameValuePairString(attrName, e.val()));
     log.debug("captured form input: " + attrName + " = " + e.val());
   }
   return false;
 }
  private void initPane() {
    //		WebEngine engine = optionView.getEngine();
    try {
      Document document = Jsoup.connect(webView.getEngine().getLocation()).get();
      Element table =
          document.select("#normal_basket_" + document.select("[name=item_id]").val()).first();
      Element td = table.select("td").first();
      Elements spans = td.select("span");
      Elements selects = td.select("select");
      //			System.out.println(spans.size());
      cmb = new ArrayList<ComboBox>();
      for (int i = 0; i < spans.size(); i++) {

        ObservableList<ValuePair> obs = FXCollections.observableArrayList();
        Elements options = selects.get(i).select("option");
        for (int k = 0; k < options.size(); k++) {
          Element option = options.get(k);
          obs.add(new ValuePair("choice", option.text(), option.val()));
        }

        cmb.add(new ComboBox<ValuePair>(obs));
        optionArea.getChildren().addAll(new Text(spans.get(i).text()), cmb.get(i));
      }

    } catch (Exception e) {
      // TODO 自動生成された catch ブロック
      e.printStackTrace();
    }
  }
Exemplo n.º 3
0
  public static String getVIEWSTATE(Document doc) {

    Element viewstate = doc.getElementById("__VIEWSTATE");
    if (viewstate == null) return null;

    return viewstate.val();
  }
Exemplo n.º 4
0
 private ViewModel parseDetail(Document doc, ViewModel item) {
   if (doc.select("select#SeasonSelection").size() > 0) {
     item.setType(ViewModel.Type.SERIES);
     String rel = doc.select("select#SeasonSelection").attr("rel");
     rel = rel.substring(rel.indexOf("SeriesID=") + "SeriesID=".length());
     item.setSeriesID(Integer.valueOf(rel));
     // Fill seasons and episodes
     Elements seasons = doc.select("select#SeasonSelection > option");
     List<Season> list = new ArrayList<Season>();
     for (Element season : seasons) {
       String[] rels = season.attr("rel").split(",");
       Season s = new Season();
       s.id = Integer.valueOf(season.val());
       s.name = season.text();
       s.episodes = rels;
       list.add(s);
     }
     item.setSeasons(list.toArray(new Season[list.size()]));
   } else {
     item.setType(ViewModel.Type.MOVIE);
     List<Host> hostlist = new ArrayList<Host>();
     Elements hosts = doc.select("ul#HosterList").select("li");
     for (Element host : hosts) {
       int hosterId = 0;
       Set<String> classes = host.classNames();
       for (String c : classes) {
         if (c.startsWith("MirStyle")) {
           hosterId = Integer.valueOf(c.substring("MirStyle".length()));
         }
       }
       String name = host.select("div.Named").text();
       String count = host.select("div.Data").text();
       int c = 1;
       if (count.contains("/")) {
         count = count.substring(count.indexOf("/") + 1, count.indexOf(" ", count.indexOf("/")));
         c = Integer.valueOf(count);
       }
       for (int i = 0; i < c; i++) {
         Host h = Host.selectById(hosterId);
         h.setName(name);
         h.setMirror(i + 1);
         if (h.isEnabled()) {
           hostlist.add(h);
         }
       }
     }
     item.setMirrors(hostlist.toArray(new Host[hostlist.size()]));
   }
   String imdb = doc.select("div.IMDBRatingLinks > a").attr("href").trim();
   if (!TextUtils.isEmpty(imdb)) {
     imdb = imdb.replace("/", "");
     item.setImdbId(imdb);
   }
   return item;
 }
Exemplo n.º 5
0
 @Override
 public Set<String> getSupportedLanguages() throws IOException {
   Set<String> langs = new HashSet<>();
   String html = httpGet(opac_url + "/Search/Advanced", getDefaultEncoding());
   Document doc = Jsoup.parse(html);
   if (doc.select("select[name=mylang]").size() > 0) {
     for (Element opt : doc.select("select[name=mylang] option")) {
       if (languageCodes.containsValue(opt.val())) {
         for (Map.Entry<String, String> lc : languageCodes.entrySet()) {
           if (lc.getValue().equals(opt.val())) {
             langs.add(lc.getKey());
             break;
           }
         }
       } else {
         langs.add(opt.val());
       }
     }
   }
   return langs;
 }
  public static void model2Form(Element dom, Object obj) {

    try {
      for (Element elm : dom.select("input, textarea")) {
        String name = elm.attr("name");
        if (name.contains(".")) {
          System.out.println("NAME " + name.split("\\.").length);
          Field field = obj.getClass().getField(name.split("\\.")[1]);
          Object value = field.get(obj);
          if (value != null) {
            elm.val(value.toString());
          }
        }
      }
    } catch (IllegalArgumentException ex) {
      Logger.getLogger(AppUtils.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
      Logger.getLogger(AppUtils.class.getName()).log(Level.SEVERE, null, ex);
    } catch (NoSuchFieldException ex) {
      Logger.getLogger(AppUtils.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
      Logger.getLogger(AppUtils.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Exemplo n.º 7
0
  @Override
  public List<SearchField> parseSearchFields()
      throws IOException, OpacErrorException, JSONException {
    start();
    String html =
        httpGet(opac_url + "/Search/Advanced?mylang = " + languageCode, getDefaultEncoding());
    Document doc = Jsoup.parse(html);

    List<SearchField> fields = new ArrayList<>();

    Elements options = doc.select("select#search_type0_0 option");
    for (Element option : options) {
      TextSearchField field = new TextSearchField();
      field.setDisplayName(option.text());
      field.setId(option.val());
      field.setHint("");
      field.setData(new JSONObject());
      field.getData().put("meaning", option.val());
      fields.add(field);
    }
    if (fields.size() == 0) {
      // Weird JavaScript, e.g. view-source:http://vopac.nlg.gr/Search/Advanced
      Pattern pattern_key = Pattern.compile("searchFields\\[\"([^\"]+)\"\\] = \"([^\"]+)\";");
      for (Element script : doc.select("script")) {
        if (!script.html().contains("searchFields")) continue;
        for (String line : script.html().split("\n")) {
          Matcher matcher = pattern_key.matcher(line);
          if (matcher.find()) {
            TextSearchField field = new TextSearchField();
            field.setDisplayName(matcher.group(2));
            field.setId(matcher.group(1));
            field.setHint("");
            field.setData(new JSONObject());
            field.getData().put("meaning", field.getId());
            fields.add(field);
          }
        }
      }
    }

    Elements selects = doc.select("select");
    for (Element select : selects) {
      if (!select.attr("name").equals("filter[]")) continue;
      DropdownSearchField field = new DropdownSearchField();
      if (select.parent().select("label").size() > 0) {
        field.setDisplayName(select.parent().select("label").first().text());
      }
      field.setId(select.attr("name") + select.attr("id"));
      List<Map<String, String>> dropdownOptions = new ArrayList<>();
      String meaning = select.attr("id");
      field.addDropdownValue("", "");
      for (Element option : select.select("option")) {
        if (option.val().contains(":")) {
          meaning = option.val().split(":")[0];
        }
        field.addDropdownValue(option.val(), option.text());
      }
      field.setData(new JSONObject());
      field.getData().put("meaning", meaning);
      fields.add(field);
    }

    return fields;
  }
Exemplo n.º 8
0
  @Override
  public List<CuriosityFare> getFare(CuriositySearch search)
      throws IOException, InterruptedException, ExecutionException {
    try {
      List<CuriosityFare> fareDepartures = Lists.newArrayList();
      List<CuriosityFare> fareArrvials = Lists.newArrayList();
      List<CuriosityFare> fares = Lists.newArrayList();
      AirfranceFlightResponseFirst responseFirst = new AirfranceFlightResponseFirst();
      Response resultFirst = responseFirst.getResponse(search);
      Document document = Jsoup.parse(resultFirst.getResponseBody());

      FluentStringsMap requestParams = new FluentStringsMap();
      for (Element element : document.select("input[type=hidden]")) {
        requestParams.add(element.attr("name"), element.val());
      }

      search.createParam("requestParam", requestParams);

      String sId = StringUtils.substringBetween(document.toString(), "var Session='", "';");
      search.createParam("sid", "JSESSIONID=" + sId);
      AirfranceFlightResponseSecond responseSecond = new AirfranceFlightResponseSecond();

      Response resultSecond = responseSecond.getResponse(search);
      String contentSecond = resultSecond.getResponseBody();

      AirfranceFlightResponseThird responseThird = new AirfranceFlightResponseThird();
      String contentThird = responseThird.getResponse(search).getResponseBody();
      Document documentThird = Jsoup.parse(contentThird);
      String currency =
          StringUtils.substringBetween(contentThird, "tc_vars_miniRecap[\"currency\"] = \"", "\";");
      Float pricePerChild = 0F;
      Float basePriceDep = 0F;
      Float basePriceArr = 0F;
      Float basePricePerAdult = 0F;
      // System.err.print(documentThird);
      if (search.getChildrenCount() > 0) {
        String[] basePricePerAdultArr =
            documentThird.select("div#idUpsellTotalPrice").text().split(" ");

        if (basePricePerAdultArr.length == 3) {
          basePricePerAdult = Float.parseFloat(basePricePerAdultArr[0] + basePricePerAdultArr[1]);
        }
        String[] totalBaseArr =
            documentThird.select("div#idUpsellTotalPriceMultiPax").text().split(" ");
        Float totalBase = 0F;
        if (totalBaseArr.length == 3) {
          totalBase = Float.parseFloat(totalBaseArr[0] + totalBaseArr[1]);
        }
        pricePerChild =
            (totalBase - (basePricePerAdult * search.getAdultsCount())) / search.getChildrenCount();
      }
      String depContent =
          StringUtils.substringBetween(
              contentThird,
              "</script> <dl> <dt class=\"etape\"> <div class=\"titre\" id=\"idUpsellTitle0\">",
              "tc_product_css = new Array();");
      if (depContent != null && !depContent.equals("")) {
        Document depDocument = Jsoup.parse(depContent);
        Elements depElements = depDocument.select("table.upsellRow");
        for (Element element : depElements) {
          Elements segmentElements = element.select("tbody>tr");
          Float pricePerAdult = 0F;
          if (segmentElements.size() > 0) {
            pricePerAdult =
                Float.parseFloat(segmentElements.get(0).select("input[name=price]").val());
          }
          Float priceTotal =
              Float.parseFloat(segmentElements.get(0).select("input[name=priceMultiPax]").val());
          List<CuriositySegment> outboundSegments = parseSegments(element);
          CuriosityFare fare = new CuriosityFare();

          // fare.setTotalPrice(pricePerAdult*search.getAdultsCount(),search);
          fare.setOutboundSegments(outboundSegments);
          fare.setCurrencyCode(currency);
          fare.setAirlineCode("AF");
          fare.setPrice(priceTotal);
          fare.setPricePerAdult(priceTotal / search.getPassengersCount());
          if (search.getChildrenCount() > 0) {
            fare.setPricePerChild(priceTotal / search.getPassengersCount());
          }
          fareDepartures.add(fare);
        }

        if (search.isRoundtrip()) {
          // System.err.print(contentThird);
          int i = 0;
          for (CuriosityFare depFare : fareDepartures) {
            search.getParams().clear();
            search.createParam("sid", "JSESSIONID=" + sId);
            search.createParam("selected", i);
            AirfranceFlightResponseFour responseFour = new AirfranceFlightResponseFour();
            String contentFour = responseFour.getResponse(search).getResponseBody();
            // System.err.print(contentFour);
            //					AirfranceFlightResponseThird newResponseThird = new
            // AirfranceFlightResponseThird();
            //					String newContentThird = newResponseThird.getResponse(search).getResponseBody();
            //	System.err.print(newContentThird);
            String arrContent =
                StringUtils.substringBetween(
                    contentThird,
                    "</script> <dl> <dt class=\"etape\"> <div class=\"titre\" id=\"idUpsellTitle1\">",
                    "tc_product_css = new Array();");
            Document arrpDocument = Jsoup.parse(contentFour);
            Elements arrElements = arrpDocument.select("table.upsellRow");
            // System.err.print(arrElements);
            for (Element element : arrElements) {
              String isCheap =
                  element
                      .select("tbody>tr")
                      .get(0)
                      .select("td.upsellRadio>span.upsellFareCheap")
                      .text();
              if (isCheap != null && !isCheap.equalsIgnoreCase("")) {
                Elements segmentElements = element.select("tbody>tr");
                Float pricePerAdult = 0F;
                if (segmentElements.size() > 0) {
                  pricePerAdult =
                      Float.parseFloat(segmentElements.get(0).select("input[name=price]").val());
                }
                List<CuriositySegment> inboundSegments = parseSegments(element);
                CuriosityFare fare = new CuriosityFare();
                fare.setOutboundSegments(depFare.getOutboundSegments());
                fare.setInboundSegments(inboundSegments);
                Float basePricePerAdultRT = depFare.getPricePerAdult();
                fare.setPricePerAdult(depFare.getPrice() / search.getPassengersCount());
                if (search.getChildrenCount() > 0) {
                  fare.setPricePerChild(depFare.getPrice() / search.getPassengersCount());
                }
                fare.setPrice(depFare.getPrice());
                fare.setCurrencyCode(currency);
                fare.setAirlineCode("AF");
                fares.add(fare);
              }
            }
            i++;
          }

        } else {
          //				if (search.getChildrenCount()>0) {
          //					for (CuriosityFare fareDep : fareDepartures) {
          //						Float basePricePerAdultOW = fareDep.getBasePricePerAdult();
          //						Float price = fareDep.getPrice();
          //						price +=
          // ((basePricePerAdultOW/basePricePerAdult)*pricePerChild)*search.getChildrenCount();
          //						fareDep.setPrice(price);
          //						fares.add(fareDep);
          //					}
          //				}else{
          fares.addAll(fareDepartures);
          //				}
        }
      }
      return fares;
    } catch (Exception e) {
      return null;
    }
  }