public Date getStartDate(StockInfo stock) throws Exception { String path = "/corp/go.php/vMS_MarketHistory/stockid/" + stock.numberToString() + ".phtml"; URI uri = new URIBuilder() .setScheme("http") .setHost("vip.stock.finance.sina.com.cn") .setPath(path) .setParameter("year", "1980") .setParameter("jidu", "1") .build(); DownloadHelper download = new DownloadHelper(uri); InputStream is = download.getInputStream(); Document doc = Jsoup.parse(inputStreamToStringBuilder(is).toString()); is.close(); download.close(); Elements select = doc.getElementsByAttributeValue("name", "year"); if (select == null) { return null; } // System.out.println(select.size()); Elements years = select.get(0).getElementsByTag("option"); String year = years.get(years.size() - 1).text(); // System.out.println(year); return Date.quarterToDate(Integer.parseInt(year), tryQuarter(stock, year)); }
private boolean extractRun(StockInfo stock, Date date) throws Exception { String path = "/corp/go.php/vMS_MarketHistory/stockid/" + stock.numberToString() + ".phtml"; URI uri = new URIBuilder() .setScheme("http") .setHost("vip.stock.finance.sina.com.cn") .setPath(path) .setParameter("year", String.valueOf(date.getYear())) .setParameter("jidu", String.valueOf(dateToQuarter(date))) .build(); DownloadHelper download = new DownloadHelper(uri); InputStream is = download.getInputStream(); boolean ret = jsoupImpl(is); is.close(); download.close(); return ret; }
private int tryQuarter(StockInfo stock, String year) throws Exception { String path = "/corp/go.php/vMS_MarketHistory/stockid/" + stock.numberToString() + ".phtml"; for (int i = 1; i <= 4; i++) { URI uri = new URIBuilder() .setScheme("http") .setHost("vip.stock.finance.sina.com.cn") .setPath(path) .setParameter("year", year) .setParameter("jidu", String.valueOf(i)) .build(); DownloadHelper download = new DownloadHelper(uri); InputStream is = download.getInputStream(); Document doc = Jsoup.parse(inputStreamToStringBuilder(is).toString()); is.close(); download.close(); Element element = doc.getElementById("FundHoldSharesTable"); if (element != null) { // find first quarter return i; } } return 1; }