Update: 定位到持仓与净值表格
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package cn.hezhaohui.fund;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package cn.hezhaohui.fund.util;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SoupUtil {
|
||||
|
||||
public Elements parseContent(String content) {
|
||||
Document document = Jsoup.parse(content);
|
||||
Elements elements = document.getElementsByClass("ui-table-hover");
|
||||
return elements;
|
||||
// Element firstTable = elements.first();
|
||||
// Element secondTable = elements.size() >= 3 ? elements.get(2) : null;
|
||||
//
|
||||
}
|
||||
|
||||
public Element getHoldings(Elements elements) {
|
||||
return !elements.isEmpty() ? elements.getFirst() : null;
|
||||
}
|
||||
|
||||
public Element getWorth(Elements elements) {
|
||||
return elements.size() >= 3 ? elements.get(2) : null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package cn.hezhaohui.fund.util;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
|
||||
@SpringBootTest
|
||||
class SoupUtilTest {
|
||||
@Resource
|
||||
private SoupUtil soupUtil;
|
||||
|
||||
@Test
|
||||
void parseContent() {
|
||||
Elements elements = soupUtil.parseContent(WebUtil.getContentByUrl(FundUtil.getUrlByFundId("001068")));
|
||||
System.out.println(elements);
|
||||
Assert.notNull(elements);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getHoldings() {
|
||||
Elements elements = soupUtil.parseContent(WebUtil.getContentByUrl(FundUtil.getUrlByFundId("001068")));
|
||||
Assert.notNull(elements);
|
||||
|
||||
Element holdings = soupUtil.getHoldings(elements);
|
||||
System.out.println(holdings);
|
||||
Assert.notNull(holdings);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWorth() {
|
||||
Elements elements = soupUtil.parseContent(WebUtil.getContentByUrl(FundUtil.getUrlByFundId("001068")));
|
||||
Assert.notNull(elements);
|
||||
|
||||
Element worth = soupUtil.getWorth(elements);
|
||||
System.out.println(worth);
|
||||
Assert.notNull(worth);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user