⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qlsh.java~55~

📁 本程序用JAVA编制
💻 JAVA~55~
字号:
import java.util.*;import java.io.*;import java.sql.Timestamp;import org.w3c.dom.*;  public class Qlsh {    private static final String source =        "http://stock.sina.com.cn/cgi-bin/stock/quote/quote.cgi?symbol=600002&country=sh&option=1";    private static final String xslFile = "new-xml/600002.xsl";    private static final String xmlFile = "new-xml/600002-result.xml";    public Qlsh(){    //public static void main(String args[]) {      try {        // Retrieve the source document as XML        Document xhtml = StockHelper.tidyHTML(source);        // Parse the XSL document        Document xsl   = StockHelper.parseXMLFromFile(xslFile);        // Get the current data by applying the XSL transform        Document data  = StockHelper.transformXML(xhtml, xsl);        // For convenience, add a timestamp to what we have done        //Document resultxml = StockHelper.parseXMLFromFile(xmlFile);        Date now = new Date();        Timestamp time = new Timestamp(now.getTime());        Element root = data.getDocumentElement();        NodeList nl = root.getElementsByTagName("stock");        Element stock = (Element)nl.item(0);        for(int i=0;i<stock.getChildNodes().getLength();i++){          String value=stock.getChildNodes().item(i).getChildNodes().item(0).getNodeValue();          stock.getChildNodes().item(i).getChildNodes().item(0).setNodeValue(value.trim());        }        String newtime=stock.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();        //System.out.println("new time="+newtime);        //Write the output file, merging if necessary        File dataFile  = new File(xmlFile);        if (dataFile.exists()) {           //If we have extracted before, merge the data and write the file          Document oldData = StockHelper.parseXMLFromFile(dataFile);          Element oldroot = oldData.getDocumentElement();          NodeList oldnl = oldroot.getElementsByTagName("stock");          Element oldstock = (Element)oldnl.item(0);          //String firsttime=oldstock.getElementsByTagName("time").item(0).getChildNodes().item(0).getNodeValue();          //System.out.println("first time="+firsttime);          int len=oldroot.getChildNodes().getLength();          String lasttime=oldroot.getChildNodes().item(len-2).getChildNodes().item(1).getChildNodes().item(0).getNodeValue();          //System.out.println("last time="+lasttime);          if(newtime.equals(lasttime)){            System.out.println("qlsh----none");          }          else{            StockHelper.mergeXML(oldData.getDocumentElement(), stock, false);            StockHelper.outputXMLToFile(oldData, xmlFile);            System.out.println("qlsh ---- ok");          }          //System.out.print(stock.getChildNodes().item(0).getChildNodes().item(0).getNodeValue());        } else {          // If this is our first extraction, just write the file          StockHelper.outputXMLToFile(data, xmlFile);        }      } catch (XMLHelperException xmlhe) {        System.err.println(            "There was an error in the extraction process:\n" + xmlhe.getMessage());      }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -