调整结构

This commit is contained in:
Achilles
2024-01-08 17:09:20 +08:00
parent 28f33672e5
commit 9264f08c77

View File

@@ -16,6 +16,7 @@ import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.io.BufferedReader; import java.io.BufferedReader;
@@ -93,9 +94,8 @@ public class MoneyScraper {
} }
@GetMapping("testScraperGetMoneyControlStockNoScId") @GetMapping("testScraperGetMoneyControlStockNoScId")
public String testScraperGetMoneyControlStockNoScId() { public String testScraperGetMoneyControlStockNoScId(@RequestParam("url") String url) {
String url = "http://www.moneycontrol.com/india/stockpricequote/foodprocessing/nestleindia/NI"; Document soup2 = fetchCompanyDetails(url);
/* Document soup2 = fetchCompanyDetails(url);
if (soup2 != null) { if (soup2 != null) {
Element comIdInput = soup2.selectFirst("input[id=ap_sc_id]"); Element comIdInput = soup2.selectFirst("input[id=ap_sc_id]");
@@ -109,19 +109,19 @@ public class MoneyScraper {
if (soup2 != null) { if (soup2 != null) {
Element ulElement = soup2.selectFirst("ul[id=nseBseTab]"); Element ulElement = soup2.selectFirst("ul[id=nseBseTab]");
String name = soup2.selectFirst("#stockName > h1").text();
if (ulElement != null) { if (ulElement != null) {
for (Element aElement : ulElement.select("a")) { for (Element aElement : ulElement.select("a")) {
String exchangeValue = aElement.text().trim(); String exchangeValue = aElement.text().trim();
if ("BSE".equals(exchangeValue) || "NSE".equals(exchangeValue)) { if ("BSE".equals(exchangeValue) || "NSE".equals(exchangeValue)) {
log.info(Thread.currentThread().getName() + ",the stock url: " + url + log.info(Thread.currentThread().getName() + ",the stock url: " + url +
", the exchange Value: " + exchangeValue); ", the exchange Value: " + exchangeValue);
MoneyStock build = MoneyStock.builder().stockName("sss").stockType(exchangeValue.toLowerCase(Locale.ROOT)) MoneyStock build = MoneyStock.builder().stockName(name).stockType(exchangeValue.toLowerCase(Locale.ROOT))
.detailUrl(String.format("https://priceapi.moneycontrol.com/pricefeed/%s/equitycash/%s", exchangeValue.toLowerCase(), companyCodeId)) .detailUrl(String.format("https://priceapi.moneycontrol.com/pricefeed/%s/equitycash/%s", exchangeValue.toLowerCase(), companyCodeId))
.selfUrl(url) .selfUrl(url)
.selfDispId(extractDispId(url)) .selfDispId(extractDispId(url))
.moneyScId(companyCodeId).saveTime(new Date()).build(); .moneyScId(companyCodeId).saveTime(new Date()).build();
List<MoneyStock> all = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.stockName.eq("Nestle"), QMoneyStockPO.moneyStockPO.stockType.eq(exchangeValue.toLowerCase(Locale.ROOT))); List<MoneyStock> all = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.stockName.eq(name), QMoneyStockPO.moneyStockPO.stockType.eq(exchangeValue.toLowerCase(Locale.ROOT)));
if (CollectionUtil.isEmpty(all)) { if (CollectionUtil.isEmpty(all)) {
moneyStockRepository.save(build); moneyStockRepository.save(build);
} }
@@ -129,7 +129,7 @@ public class MoneyScraper {
} }
} }
} }
}*/ }
return "ok"; return "ok";
} }