Esempio n. 1
0
  public boolean checkprice() {
    System.out.println("checking amazon url:" + page.url);
    try {

      URL url = new URL(page.url);
      HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
      urlConnection.setConnectTimeout(Constant.connect_timeout);

      Parser parser = new Parser(urlConnection);
      parser.setEncoding(Constant.ENCODE);

      // OrFilter lastFilter = new OrFilter();
      // lastFilter.setPredicates(new NodeFilter[] {
      // new NodeClassFilter(TableTag.class),
      // new NodeClassFilter(Div.class) });
      //
      // NodeList list = parser.extractAllNodesThatMatch(lastFilter);

      NodeList list = parser.extractAllNodesThatMatch(new NodeClassFilter(Div.class));
      System.out.println("size:" + list.size());

      for (int i = 0; i < list.size(); i++) {
        Node tag = list.elementAt(i);

        if (tag instanceof Div) {
          Div d = (Div) tag;
          System.out.println(d.getAttribute("id"));

          if (d.getAttribute("id").startsWith("result_")) {
            // found one product
            try {
              AmazonProduct product = new AmazonProduct();
              product.name = d.getAttribute("name");
              getPriceAndLabel(d, product);

            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        }
      }

    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
    return false;
  }
Esempio n. 2
0
 private void getPriceAndLabel(Node node, AmazonProduct product) throws Exception {
   NodeList childList = node.getChildren();
   List<String> productvalue = new ArrayList<String>();
   processNodeList(childList, productvalue);
   System.out.println(productvalue);
   product.label = productvalue.get(0);
   // String price = productvalue.get(3);
   // product.price = getprice(price);
 }