数据导入方法,添加初始对象处理
This commit is contained in:
parent
7b08de5d8a
commit
98a493cf8c
@ -1,35 +1,22 @@
|
||||
package com.usvisatrack.services;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.GnuParser;
|
||||
import org.apache.commons.httpclient.util.URIUtil;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import com.usvisatrack.core.dao.model.Visa;
|
||||
import com.usvisatrack.core.factories.VisaFactory;
|
||||
import com.usvisatrack.services.common.DataCrawl;
|
||||
|
||||
/**
|
||||
@ -87,6 +74,37 @@ public class VisaImporter extends DataCrawl {
|
||||
private void crawlWebItem() {
|
||||
|
||||
logger.error("Crawl Web Data to load item info.");
|
||||
List<Visa> visaList = new ArrayList<Visa>();
|
||||
|
||||
Document doc = null;
|
||||
|
||||
try {
|
||||
doc = Jsoup.connect("https://www.checkee.info/main.php?dispdate=2017-07").get();
|
||||
Elements newsHeadlines = doc.select("table");
|
||||
Element table = newsHeadlines.get(6);
|
||||
|
||||
int i = 0;
|
||||
for (Element row : table.select("tr")) {
|
||||
i++;
|
||||
Elements tds = row.select("td");
|
||||
|
||||
if (!StringUtils.equalsIgnoreCase("ID", tds.get(1).text())) {
|
||||
Visa visa = new Visa();
|
||||
visa.setMajor(StringUtils.trimToEmpty(tds.get(5).text()));
|
||||
logger.debug("[{}]", visa.getMajor());
|
||||
|
||||
VisaFactory.save(visa);
|
||||
}
|
||||
|
||||
if (i == 2)
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user