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

📄 qlsh1.java

📁 本程序用JAVA编制
💻 JAVA
字号:
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=15&eMin=30";  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();      int root_len=root.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));      }      //System.out.println(root.getChildNodes().getLength());      // 删除多余空格      for(int k=0;k<root_len;k++){System.out.println(root.getChildNodes().item(k));      System.out.println(k);        /*for(int j=0;j<stock_len;j++){          //stock.getChildNodes().item(j).getChildNodes().item(0).setNodeValue(value.trim());          System.out.println(root.getChildNodes().item(k));          if(stock.getChildNodes().item(j).getChildNodes().item(0)!=null){            String value=stock.getChildNodes().item(j).getChildNodes().item(0).getNodeValue();            stock.getChildNodes().item(j).getChildNodes().item(0).getNodeValue().trim();            System.out.println(stock.getChildNodes().item(j).getChildNodes().item(0).getNodeValue());          }        }*/      }      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);        StockHelper.mergeXML(oldData.getDocumentElement(), stock, false);      } 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 + -