コード例 #1
0
ファイル: Utilities.java プロジェクト: nghoang/jCrawlerLib
  public static boolean CompareApproximate(String group1, String group2) {
    boolean res = false;
    group1 = Utilities.RemoveSpace(group1.replaceAll("[^a-zA-Z0-9]", " ").toLowerCase());
    group2 = Utilities.RemoveSpace(group2.replaceAll("[^a-zA-Z0-9]", " ").toLowerCase());

    String[] terms1 = group1.split(" ");
    String[] terms2 = group2.split(" ");

    res = true;
    for (String term : terms1) {
      if (group2.indexOf(term) == -1) {
        res = false;
        break;
      }
    }

    if (res == false) {
      res = true;
      for (String term : terms2) {
        if (group1.indexOf(term) == -1) {
          res = false;
          break;
        }
      }
    }

    return res;
  }
コード例 #2
0
ファイル: Utilities.java プロジェクト: nghoang/jCrawlerLib
 public static void WriteLog(String log, int nbLines) {
   if (nbLines == -1) {
     WriteFile("log.txt", getDateTime() + " >> " + log + "\n", true);
   } else {
     try {
       FileInputStream fstream = new FileInputStream("log.txt");
       DataInputStream in = new DataInputStream(fstream);
       BufferedReader br = new BufferedReader(new InputStreamReader(in));
       String strLine;
       Vector<String> totalLines = new Vector<String>();
       while ((strLine = br.readLine()) != null) {
         totalLines.add(strLine);
       }
       if (totalLines.size() > nbLines) {
         String content = "";
         for (int i = totalLines.size() - nbLines; i <= totalLines.size() - 1; i++) {
           content += totalLines.get(i) + "\n";
         }
         WriteFile("log.txt", content, false);
       }
       in.close();
     } catch (Exception e) {
       Utilities.WriteLogTrace(e);
     }
     WriteLog(log);
   }
 }
コード例 #3
0
ファイル: Utilities.java プロジェクト: nghoang/jCrawlerLib
 public static long GetWorldTime() {
   try {
     WebClientX client = new WebClientX();
     String content = client.GetMethod("http://www.unixtimestamp.com/index.php");
     content = Utilities.SimpleRegexSingle("<font color=\"#CC0000\">([^<]*)</font>", content, 1);
     return Long.parseLong(content);
   } catch (Exception ex) {
     // ex.printStackTrace();
     return 0;
   }
 }
コード例 #4
0
ファイル: Utilities.java プロジェクト: nghoang/jCrawlerLib
 public static String OnlineCaptchaSolving(String filename) {
   WebClientX client = new WebClientX();
   Vector<NameValuePair> prs = new Vector<NameValuePair>();
   prs.add(new BasicNameValuePair("i2ocr_options", "file"));
   prs.add(new BasicNameValuePair("i2ocr_url", "http://"));
   prs.add(new BasicNameValuePair("i2ocr_languages", "gb"));
   Vector<PostFileData> files = new Vector<PostFileData>();
   files.add(
       new PostFileData("i2ocr_uploadedfile", "/Users/hoangong/projects/Java/Bet/" + filename));
   String content = client.PostMethod("http://www.sciweavers.org/process_form_i2ocr", prs, files);
   content =
       Utilities.SimpleRegexSingle(
           "#ocrTextBox\"\\).val\\(\"(.*?)(?=\"\\);\\$\\(\"#ocrTextBox\")", content, 1);
   return "";
 }
コード例 #5
0
ファイル: Utilities.java プロジェクト: nghoang/jCrawlerLib
 public static void WriteSetting(String file, String name, String value) {
   try {
     if (IsFileExist(file + ".xml") == false) {
       WriteFile(file + ".xml", "<settings></settings>", false);
     }
     DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
     DocumentBuilder builder = domFactory.newDocumentBuilder();
     Document doc = builder.parse(new File(file + ".xml"));
     NodeList list = doc.getElementsByTagName(name);
     if (list.getLength() > 0) {
       Node node = (Node) doc.createElement(name);
       node.setTextContent(value);
       doc.getElementsByTagName("settings").item(0).replaceChild(node, list.item(0));
     } else {
       Element node = doc.createElement(name);
       node.setTextContent(value);
       doc.getElementsByTagName("settings").item(0).appendChild(node);
     }
     Utilities.WriteXML(file + ".xml", doc, false);
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }