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

📄 qlsh1.java~51~

📁 本程序用JAVA编制
💻 JAVA~51~
字号:
import java.util.*;import java.io.*;import java.sql.Timestamp;import org.w3c.dom.*;public class Qlsh1 {  private static final String source =      "http://quote.stockstar.com/stock/external_dealm.asp?target=dealm&code=shag600002&sHour=9&sMin=29&eHour=10&eMin=40";  private static final String xslFile = "new-xml/stock/600002.xsl";  private static final String xmlFile = "new-xml/stock/2.xml";  //public Qlsh1(){  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");      //NodeList nl = root.getChildNodes().item(0).getChildNodes();      Element stock = (Element)nl.item(0);      int stock_len=stock.getChildNodes().getLength();      // 删除非数值数据(表头的汉字)      for(int i=0;i<2;i++){        //System.out.println(root.getChildNodes().item(i).getChildNodes().item(0).getChildNodes().item(0).getNodeValue());        root.removeChild(root.getChildNodes().item(0));      }      // 删除多余空格      for(int j=0;j<stock_len;j++){        //String value=stock.getChildNodes().item(j).getChildNodes().item(0).getNodeValue();        //stock.getChildNodes().item(j).getChildNodes().item(0).setNodeValue(value.trim());        System.out.println(stock.getChildNodes().item(j).getChildNodes().item(0).getNodeValue());      }      //String newtime=stock.getChildNodes().item(4).getChildNodes().item(0).getNodeValue();      //System.out.println(root);      //System.out.println(root.getChildNodes().item(0));      //System.out.println(stock.getChildNodes().item(0).getChildNodes().item(0).getNodeValue().trim());      //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  "+newtime);          }*/        //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 + -