Exemplo n.º 1
0
        public static string GetStockPic()
        {
            string xmlString = string.Empty;

            //http://quotes.cnfol.com/searchFile/ajax.xml

            HttpService web = new HttpService();
            web.TargetUrl = "http://hq.sinajs.cn/list=sh000001_zdp,sz399001_zdp,sh000300_zdp,sz399107_zdp,";
            web.RefererUrl = "http://hq.sinajs.cn/";
            web.UserAgent = "StockTrace";
            string htmlContent = web.GetHttp(true, false);
            xmlString = htmlContent;
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xmlString);
            XmlNode list = doc.SelectSingleNode("/neverModules/autocomplete/dataSource");
            return xmlString;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 查询某地区某运营商充值价格
        /// </summary>
        /// <param name="provinceID">省ID</param>
        /// <param name="netID">运营商ID(中移动:0,中联通:1)</param>
        /// <returns>某地区某运营商充值价格</returns>
        public static string[] SearchMainPrice()
        {
            string[] info = new string[2];
            string priceHtml = string.Empty;
            lock (obj)
            {
                HttpService web = new HttpService();
                web.TargetUrl = "http://www.google.cn/finance";
                web.RefererUrl = "http://www.google.cn/";
                string htmlContent = web.GetHttp(true, true);

                HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlDocument();
                htmlDoc.LoadHtml(htmlContent);

                HtmlNode infoTableNode = htmlDoc.GetElementbyId("md");
                if (infoTableNode == null)
                {
                    return info;
                }

                HtmlNodeCollection spans = infoTableNode.SelectNodes("tr//td//span");

                int exitFlg = 0;
                foreach (HtmlNode span in spans)
                {
                    //if (span.GetAttributeValue("class", "") == "pr")
                    //{
                    //    info.PriceNow = spans[0].InnerText;
                    //    exitFlg++;
                    //}
                    //if (span.GetAttributeValue("class", "") == "chr" && !span.InnerText.Contains("%"))
                    //{
                    //    info.PriceChange = spans[1].InnerText;
                    //    exitFlg++;
                    //}
                    //if (span.GetAttributeValue("class", "") == "chr" && span.InnerText.Contains("%"))
                    //{
                    //    info.Range = spans[3].InnerText;
                    //    exitFlg++;
                    //}
                    //if (exitFlg == 3)
                    //{
                    //    break;
                    //}
                }
            }
            return info;
        }
Exemplo n.º 3
0
        public static List<SingleInfo> StockTrace(List<string> stockCode)
        {
            List<SingleInfo> infos = new List<SingleInfo>();
            Regex matchSH = new Regex(@"sh\d{6}");
            Regex matchSZ = new Regex(@"sz\d{6}");
            lock (obj)
            {

                string xmlString = string.Empty;
                string stockCodeString = string.Empty;
                foreach (string code in stockCode)
                {
                    //stockCodeString += code.StartsWith("6") ?
                    //    string.Concat("sh", code) : string.Concat("sz", code);
                    stockCodeString += code;
                    stockCodeString += ",";
                }
                if (stockCodeString.Length > 0)
                {
                    HttpService web = new HttpService();
                    web.TargetUrl = "http://hq.sinajs.cn/list=" + stockCodeString;
                    web.RefererUrl = "http://hq.sinajs.cn/";
                    web.UserAgent = "StockTrace";
                    string htmlContent = web.GetHttp(true, false);

                    string[] stockInfo = htmlContent.Trim().Split(
                        new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

                    #region 字符串说明
                    /*
                    00 var hq_str_sh600054="黄山旅游
                    01 15.19  昨开
                    02 15.19  今开
                    03 15.38  当前价格
                    04 15.65  最高
                    05 15.10  最低
                    06 15.38  委买
                    07 15.40  委卖
                    08 1498067   成交量
                    09 23140724  成交额
                    10 4500      买1
                    11 15.38
                    12 5862      买2
                    13 15.36
                    14 18700      买3
                    15 15.35
                    16 5000       买4
                    17 15.34
                    18 7300      买5
                    19 15.33
                    20 52100      卖1
                    21 15.40
                    22 900       卖2
                    23 15.41
                    24 3000         卖3
                    25 15.44
                    26 2800         卖4
                    27 15.45
                    28 500           买5
                    29 15.48
                    30 2009-03-12  日期
                    31 11:35:41"   时间
                     */
                    #endregion

                    foreach (string item in stockInfo)
                    {
                        int index = item.IndexOf('=');
                        if (index == -1)
                            continue;
                        string itemTemp = item.Substring(item.IndexOf('=') + 1).Replace("\"", "");
                        string[] OneStockInfo = itemTemp.Split(',');
                        //代码
                        string code = matchSH.Match(item).Value;
                        if (string.IsNullOrEmpty(code))
                        {
                            code = matchSZ.Match(item).Value;
                        }
                        //明细
                        if (OneStockInfo.Length == 32)
                        {
                            SingleInfo singleItem = new SingleInfo();
                            singleItem.StockCode = code;
                            singleItem.Name = OneStockInfo[0];
                            singleItem.YesterdayPrice = OneStockInfo[1];
                            singleItem.TodayPrice = OneStockInfo[2];
                            singleItem.PriceNow = OneStockInfo[3];
                            singleItem.HighPrice = OneStockInfo[4];
                            singleItem.LowPrice = OneStockInfo[5];
                            singleItem.ConsignBuyPrice = OneStockInfo[6];
                            singleItem.ConsignSellPrice = OneStockInfo[7];
                            singleItem.Turnover = OneStockInfo[8];
                            singleItem.TradingVolume = OneStockInfo[9];
                            singleItem.Buy1 = OneStockInfo[10];
                            singleItem.Buy1Price = OneStockInfo[11];
                            singleItem.Buy2 = OneStockInfo[12];
                            singleItem.Buy2Price = OneStockInfo[13];
                            singleItem.Buy3 = OneStockInfo[14];
                            singleItem.Buy3Price = OneStockInfo[15];
                            singleItem.Buy4 = OneStockInfo[16];
                            singleItem.Buy4Price = OneStockInfo[17];
                            singleItem.Buy5 = OneStockInfo[18];
                            singleItem.Buy5Price = OneStockInfo[19];
                            singleItem.Sell1 = OneStockInfo[20];
                            singleItem.Sell1Price = OneStockInfo[21];
                            singleItem.Sell2 = OneStockInfo[22];
                            singleItem.Sell2Price = OneStockInfo[23];
                            singleItem.Sell3 = OneStockInfo[24];
                            singleItem.Sell3Price = OneStockInfo[25];
                            singleItem.Sell4 = OneStockInfo[26];
                            singleItem.Sell4Price = OneStockInfo[27];
                            singleItem.Sell5 = OneStockInfo[28];
                            singleItem.Sell5Price = OneStockInfo[29];
                            singleItem.DataDate = OneStockInfo[30];
                            singleItem.DataTime = OneStockInfo[31];
                            infos.Add(singleItem);
                        }
                    }
                }
            }
            return infos;
        }
Exemplo n.º 4
0
        /// <summary>
        /// 查询某地区某运营商充值价格
        /// </summary>
        /// <param name="provinceID">省ID</param>
        /// <param name="netID">运营商ID(中移动:0,中联通:1)</param>
        /// <returns>某地区某运营商充值价格</returns>
        public static List<SingleInfo> SearchMore(string id)
        {
            List<SingleInfo> infos = new List<SingleInfo>();
            string priceHtml = string.Empty;
            lock (obj)
            {
                HttpService web = new HttpService();
                web.TargetUrl = string.Format("http://www.google.cn/finance?q={0}", id);
                web.RefererUrl = "http://www.google.cn/";
                string htmlContent = web.GetHttp(true, true);

                //HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlDocument();
                //htmlDoc.LoadHtml(htmlContent);

                //HtmlNode infoTableNode = htmlDoc.GetElementbyId("md");
                //if (infoTableNode == null)
                //{
                //    return info;
                //}

                //HtmlNodeCollection spans = infoTableNode.SelectNodes("tr//td//span");

                //int exitFlg = 0;
                //foreach (HtmlNode span in spans)
                //{
                //    if (span.GetAttributeValue("class", "") == "pr")
                //    {
                //        info.PriceNow = spans[0].InnerText;
                //        exitFlg++;
                //    }
                //    if (span.GetAttributeValue("class", "") == "chr" && !span.InnerText.Contains("%"))
                //    {
                //        info.PriceChange = spans[1].InnerText;
                //        exitFlg++;
                //    }
                //    if (span.GetAttributeValue("class", "") == "chr" && span.InnerText.Contains("%"))
                //    {
                //        info.Range = spans[3].InnerText;
                //        exitFlg++;
                //    }
                //    if (exitFlg == 3)
                //    {
                //        break;
                //    }
                //}
            }
            return infos;
        }