Commit b9984a89 authored by litianle's avatar litianle

添加大润发

parent 7e3262e5
package com.deeprec.crawler.modules.RTMart.crawler;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import com.deeprec.crawler.entry.CrawlerStore;
import com.deeprec.crawler.mapper.InsertDB;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
@Slf4j
public class RTMartCrawler {
private static final String SK_NAME = "大润发";
private static final String URL = "https://www.rt-mart.com.cn/stores/store?size=1200";
public static void main(String[] args) {
String response = HttpUtil.createGet("https://www.rt-mart.com.cn/stores/store")
.form("size", 1200)
.execute().body();
Document document = Jsoup.parse(response);
Element stores = document.getElementsByClass("content-store__list").get(0);
Elements storeList = stores.getElementsByClass("store-right");
for (Element store : storeList) {
Element a = store.getElementsByTag("a").get(0);
String name = a.text();
Element storeInfo = store.getElementsByClass("store-right__info").get(0);
Elements ps = storeInfo.getElementsByTag("p");
String openingHours = "", address = "", serviceTel = "", groupTel = "";
for (Element p : ps) {
String[] split = p.text().split(":");
if (split[0].equals("营业时间")) {
openingHours = split[1];
}
if (split[0].equals("门店地址")) {
address = split[1];
}
if (split[0].equals("服务电话")) {
serviceTel = split[1];
}
if (split[0].equals("团购电话")) {
groupTel = split[1];
}
}
String storeBus = "";
if (storeInfo.getElementsByTag("a").size() != 0) {
storeBus = URL + storeInfo.getElementsByTag("a").get(0).attr("href");
}
CrawlerStore crawlerStore = new CrawlerStore().setCrawlerUrl(URL)
.setSkName(SK_NAME)
.setPhone(serviceTel)
.setName(name)
.setAddress(address)
.setExtInfo(new JSONObject()
.set("openingHours", openingHours)
.set("groupTel", groupTel)
.set("storeBus", storeBus));
InsertDB.getDB().insert(crawlerStore);
log.info("区域: {},{}", crawlerStore.getAddress(), crawlerStore);
}
log.info("大润发全部插入完成");
}
}
......@@ -43,7 +43,7 @@ public class SevenElevenCrawler {
.setExtInfo(new JSONObject()
.set("openDate", store.getOpenDate())
.set("cityFullName", store.getCityFullName()));
// InsertDB.getDB().insert(crawlerStore);
InsertDB.getDB().insert(crawlerStore);
log.info("区域: {},{}", crawlerStore.getAddress(), crawlerStore);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment