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)); }
public String extract(StockInfo stock, Date date) throws Exception { String trans; if (year == date.getYear() && quarter == dateToQuarter(date)) { trans = map.get(date.toString()); } else { map = new HashMap<String, String>(70); if (extractRun(stock, date)) { year = date.getYear(); quarter = dateToQuarter(date); trans = map.get(date.toString()); } else { year = Utils.valType.NL; quarter = Utils.valType.NL; trans = null; } } return trans; }
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 dateToQuarter(Date date) { return (date.getMonth() - 1) / 3 + 1; }