예제 #1
0
 private ArrayList<City> getCitys() {
   ArrayList<City> result = new ArrayList<>();
   ArrayList<String> urlsPages = getPagesUrls();
   if (urlsPages == null) {
     return null;
   }
   for (String urlPage : urlsPages) {
     InternetConnection connection = null;
     String page = null;
     try {
       connection = new InternetConnection(urlPage);
       page = connection.getPageFromGzip();
     } catch (IOException e) {
       return null;
     } finally {
       if (connection != null) {
         connection.disconnect();
       }
     }
     Matcher matcher =
         Pattern.compile(
                 "<a data-toggle=\"tooltip\" title=\"[^\"]*\" href=\"[^\"]+\"><span class=\"text\">[^<]+</span>")
             .matcher(page);
     while (matcher.find()) {
       String region = "";
       String name = "";
       String url = "";
       String findedString = matcher.group();
       Matcher matcherRegion = Pattern.compile("title=\"[^\"]*").matcher(findedString);
       if (matcherRegion.find()) {
         region = matcherRegion.group().substring(7);
       }
       Matcher matcherName = Pattern.compile("text\">[^<]+").matcher(findedString);
       if (matcherName.find()) {
         name = matcherName.group().substring(6);
       }
       Matcher matcherUrl = Pattern.compile("href=\"[^\"]+").matcher(findedString);
       if (matcherUrl.find()) {
         url = matcherUrl.group().substring(6);
       }
       City city = new City(region, name, url);
       if (!result.contains(city)) {
         result.add(city);
       }
     }
   }
   return result;
 }
예제 #2
0
  private ArrayList<Shop> getShops() {
    ArrayList<Shop> result = new ArrayList<>();
    InternetConnection connection = null;
    String pageInString = null;
    try {
      connection = new InternetConnection(SD.BASE_URL + category.getUrl());
      pageInString = connection.getPageFromGzip();
    } catch (IOException e) {
      return null;
    } finally {
      if (connection != null) {
        connection.disconnect();
      }
    }

    Matcher matcherShop =
        Pattern.compile(
                "<a data-placement=\"left\" data-toggle=\"tooltip\" title=\"[^\"]*\" href=\"[^\"]*\"> <span class=\"img\"><img src=\"[^\"]*\" alt=\"\" /></span> <span class=\"text\">[^<]*</span>")
            .matcher(pageInString);
    while (matcherShop.find()) {
      String url = "";
      String name = "";
      String image = "";
      String foundedString = matcherShop.group();
      if (!foundedString.contains(category.getName())) {
        continue;
      }
      Matcher matcherUrl = Pattern.compile("href=\"[^\"]+").matcher(foundedString);
      if (matcherUrl.find()) {
        url = matcherUrl.group().substring(6);
      }
      Matcher matcherName = Pattern.compile("<span class=\"text\">[^<]*").matcher(foundedString);
      if (matcherName.find()) {
        name = matcherName.group().substring(19);
      }
      Matcher matcherImage = Pattern.compile("src=\"[^\"]+").matcher(foundedString);
      if (matcherImage.find()) {
        image = matcherImage.group().substring(5).replaceFirst("\\-[0-9]+\\.", ".");
      }
      Shop shop = new Shop(name, image, city, category.getUrl(), url, "false");
      if (!result.contains(shop)) {
        result.add(shop);
      }
    }

    return result;
  }
예제 #3
0
 private ArrayList<String> getPagesUrls() {
   ArrayList<String> result = new ArrayList<>();
   InternetConnection connection = null;
   String page = null;
   try {
     connection = new InternetConnection(SD.URL_CITYS);
     page = connection.getPageFromGzip();
   } catch (IOException e) {
     return null;
   } finally {
     if (connection != null) {
       connection.disconnect();
     }
   }
   if (page != null && !page.isEmpty()) {
     Matcher matcherUrls = Pattern.compile("cities/\\?a=[^\"]+").matcher(page);
     while (matcherUrls.find()) {
       String findedString = matcherUrls.group();
       result.add(SD.BASE_URL + findedString);
     }
   }
   return result;
 }