제주도렌트카업체 정보 크롤링 기능 추가

main
이범준 3 months ago
parent 0c598051ef
commit 39ddf2147e

@ -136,6 +136,13 @@
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.21.2</version>
</dependency>
<dependency> <dependency>
<groupId>cokr.xit.base</groupId> <groupId>cokr.xit.base</groupId>
<artifactId>xit-crypto</artifactId> <artifactId>xit-crypto</artifactId>

@ -1,11 +1,21 @@
package externalsystem.testpool.web; package externalsystem.testpool.web;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import cokr.xit.foundation.data.DataObject;
import cokr.xit.foundation.web.AbstractController; import cokr.xit.foundation.web.AbstractController;
import externalsystem.testpool.RandomUtil; import externalsystem.testpool.RandomUtil;
import externalsystem.testpool.dao.TestPoolMapper; import externalsystem.testpool.dao.TestPoolMapper;
@ -43,4 +53,103 @@ public class TestPoolController extends AbstractController {
return mav; return mav;
} }
@RequestMapping(name="제주도 렌트카 업체 정보 크롤링", value="/jejuRent.do")
public ModelAndView jejuRent() throws Exception {
ModelAndView mav = new ModelAndView("jsonView");
String site = "https://bizno.net";
String listSearch = "/상호명으로사업자등록번호조회";
List<String> detailUrls = new ArrayList<String>();
List<DataObject> rentEntInfos = new ArrayList<DataObject>();
Document XM = Jsoup.connect(site+listSearch)
.data("area","제주","query","렌트카")
.get();
Elements titles1 = XM.getElementsByTag("body").get(0).getElementsByClass("titles");
for(Element title : titles1) {
String detailUrl = site+title.getElementsByTag("a").get(0).attr("href");
detailUrls.add(detailUrl);
}
Document XJ = Jsoup.connect(site+listSearch)
.data("area","제주","query","렌터카")
.get();
Elements titles2 = XJ.getElementsByTag("body").get(0).getElementsByClass("titles");
for(Element title : titles2) {
String detailUrl = site+title.getElementsByTag("a").get(0).attr("href");
detailUrls.add(detailUrl);
}
for(String detailUrl : detailUrls) {
Document detail = Jsoup.connect(detailUrl).get();
String entName = detail.getElementsByTag("h1").get(0).text();
Element table = detail.getElementsByClass("table_guide01").get(0);
String sa = table.getElementsContainingOwnText("사업자등록번호").next().text();
String beob = table.getElementsContainingOwnText("법인등록번호").next().text();
String tel = table.getElementsContainingOwnText("전화번호").next().text();
String fax = table.getElementsContainingOwnText("팩스번호").next().text();
String mail = table.getElementsContainingOwnText("회사이메일").next().text();
String daepyo = table.getElementsContainingOwnText("대표자명").next().text();
String postNo = table.getElementsContainingOwnText("우편번호").next().text();
String juso = table.getElementsContainingOwnText("회사주소").next().text();
DataObject rentEntInfo = new DataObject();
rentEntInfo.put("기업명", entName);
rentEntInfo.put("사업자등록번호", sa);
rentEntInfo.put("법인등록번호", beob);
rentEntInfo.put("전화번호", tel);
rentEntInfo.put("팩스번호", fax);
rentEntInfo.put("회사이메일", mail);
rentEntInfo.put("대표자명", daepyo);
rentEntInfo.put("우편번호", postNo);
rentEntInfo.put("회사주소", juso);
rentEntInfos.add(rentEntInfo);
}
mav.addObject("result", rentEntInfos);
return mav;
}
@RequestMapping(name="(주)제주렌트카 정보 크롤링", value="/jejuRent2.do")
@ResponseBody
public String jejuRent2() throws Exception {
Document detail = Jsoup.connect("https://bizno.net/article/6168101496").get();
String entName = detail.getElementsByTag("h1").get(0).text();
Element table = detail.getElementsByClass("table_guide01").get(0);
String sa = table.getElementsContainingOwnText("사업자등록번호").next().text();
String beob = table.getElementsContainingOwnText("법인등록번호").next().text();
String tel = table.getElementsContainingOwnText("전화번호").next().text();
String fax = table.getElementsContainingOwnText("팩스번호").next().text();
String mail = table.getElementsContainingOwnText("회사이메일").next().text();
String daepyo = table.getElementsContainingOwnText("대표자명").next().text();
String postNo = table.getElementsContainingOwnText("우편번호").next().text();
List<TextNode> tns = table.getElementsContainingOwnText("회사주소").next().textNodes();
List<String> juso = new ArrayList<String>();
for(TextNode tn : tns) {
juso.add(tn.text());
}
DataObject rentEntInfo = new DataObject();
rentEntInfo.put("기업명", entName);
rentEntInfo.put("사업자등록번호", sa);
rentEntInfo.put("법인등록번호", beob);
rentEntInfo.put("전화번호", tel);
rentEntInfo.put("팩스번호", fax);
rentEntInfo.put("회사이메일", mail);
rentEntInfo.put("대표자명", daepyo);
rentEntInfo.put("우편번호", postNo);
rentEntInfo.put("회사주소", juso);
return toJson(rentEntInfo);
}
} }

Loading…
Cancel
Save