コード例 #1
0
        public void Execute(IJobExecutionContext context)
        {
            logger.Info("Start job Tonghuashunxuangu2");
            string    sqlstring = @"select * from tonghuashunxuangu";
            DataSet   ds        = Dbhelper.ExecuteDataset(Dbhelper.Conn, CommandType.Text, sqlstring, null);
            DataTable data      = ds.Tables[0];

            TonghuashunCommon common   = new TonghuashunCommon();
            List <string>     proxyUrl = common.GetProxyURL(logger);

            for (int i = 0; i < data.Rows.Count; i++)
            {
                string url = data.Rows[i]["url"].ToString();
                string id  = data.Rows[i]["ID"].ToString();
                common.SaveDataJSON(url, id, logger, "tonghuashunxuangu2", proxyUrl);
            }
            ;
            logger.Info("End job Tonghuashunxuangu2");
        }
コード例 #2
0
        public async void Execute(IJobExecutionContext context)
        {
            logger.Info("Start job Tonghuashunxuangu");

            string  sqlstring = @"SELECT secondtitle FROM tonghuashunxuangu";
            DataSet ds        = Dbhelper.ExecuteDataset(Dbhelper.Conn, CommandType.Text, sqlstring, null);

            data = ds.Tables[0];

            string URLAddress = "http://www.iwencai.com/stockpick?tid=stockpick&ts=1&qs=1";

            //WebClient client = new WebClient();
            //client.Encoding = System.Text.Encoding.GetEncoding("UTF-8");
            try
            {
                TonghuashunCommon common = new TonghuashunCommon();
                proxyUrl = common.GetProxyURL(logger);

                string html = await common.GetHtml(URLAddress, logger, proxyUrl, "UTF-8");

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

                htmlDoc.LoadHtml(html);
                HtmlNode Node1    = htmlDoc.DocumentNode;
                var      trnodes1 = Node1.SelectNodes("//*[@id=\"area_list\"]/div");
                if (trnodes1 != null)
                {
                    foreach (var item in trnodes1)
                    {
                        var firsttitle = item.SelectSingleNode("child::h4[1]").SelectSingleNode("child::span[1]").InnerText.Trim();
                        if (firsttitle == "火力推荐")
                        {
                            var hltj = Node1.SelectNodes("//*[@id=\"hltj_right_hc_query_li_st\"]/ul/li");
                            if (hltj != null)
                            {
                                foreach (var item2 in hltj)
                                {
                                    var typename    = item2.SelectSingleNode("child::span[1]").InnerText.Trim();
                                    var secondtitle = item2.SelectSingleNode("child::div[1]").SelectSingleNode("child::a[1]").InnerText.Trim();
                                    var url         = item2.SelectSingleNode("child::div[1]").SelectSingleNode("child::a[1]").Attributes["href"].Value;

                                    SaveDataDB(firsttitle, typename, secondtitle, url);
                                }
                            }
                        }
                        if (firsttitle == "问句集锦")
                        {
                            var wjjj = Node1.SelectNodes("//*[@id=\"lm_zxwj\"]/dl");
                            if (wjjj != null)
                            {
                                foreach (var item2 in wjjj)
                                {
                                    var secondtitle = item2.SelectSingleNode("child::dd[1]").SelectSingleNode("child::a[1]").InnerText.Trim();
                                    var url         = item2.SelectSingleNode("child::dd[1]").SelectSingleNode("child::a[1]").Attributes["href"].Value;
                                    SaveDataDB(firsttitle, "", secondtitle, url);
                                }
                            }
                            var jdwj = Node1.SelectNodes("//*[@id=\"lm_jdwj\"]/dl");
                            if (jdwj != null)
                            {
                                foreach (var item2 in jdwj)
                                {
                                    var secondtitle = item2.SelectSingleNode("child::dd[1]").SelectSingleNode("child::a[1]").InnerText.Trim();
                                    var url         = item2.SelectSingleNode("child::dd[1]").SelectSingleNode("child::a[1]").Attributes["href"].Value;
                                    SaveDataDB(firsttitle, "", secondtitle, url);
                                }
                            }
                        }
                        if (firsttitle == "技术指标")
                        {
                            var jszb = Node1.SelectNodes("//*[@id=\"area_list\"]/div[4]/div/div/div/div/div/dl");
                            jishuzhibiao(jszb, firsttitle);
                        }
                        if (firsttitle == "形态选股")
                        {
                            var xtxg = Node1.SelectNodes("//*[@id=\"area_list\"]/div[5]/div/div/div/div/div/dl");
                            jishuzhibiao(xtxg, firsttitle);
                        }
                        if (firsttitle == "行情指标")
                        {
                            var xtxg = Node1.SelectNodes("//*[@id=\"area_list\"]/div[7]/div/div/div/div/div/dl");
                            jishuzhibiao(xtxg, firsttitle);
                        }
                        if (firsttitle == "牛股抓选")
                        {
                            var xtxg = Node1.SelectNodes("//*[@id=\"area_list\"]/div[8]/div/div/div/div/div/dl");
                            jishuzhibiao(xtxg, firsttitle);
                        }
                        if (firsttitle == "持股周期")
                        {
                            var xtxg = Node1.SelectNodes("//*[@id=\"area_list\"]/div[9]/div/div/div/div/div/dl");
                            jishuzhibiao(xtxg, firsttitle);
                        }
                        if (firsttitle == "股本股东")
                        {
                            var xtxg = Node1.SelectNodes("//*[@id=\"area_list\"]/div[10]/div/div/div/div/div/dl");
                            jishuzhibiao(xtxg, firsttitle);
                        }
                        if (firsttitle == "主力动向")
                        {
                            var xtxg = Node1.SelectNodes("//*[@id=\"area_list\"]/div[11]/div/div/div/div/div/dl");
                            jishuzhibiao(xtxg, firsttitle);
                        }
                        if (firsttitle == "特色数据")
                        {
                            var xtxg = Node1.SelectNodes("//*[@id=\"area_list\"]/div[12]/div/div/div/div/div/dl");
                            jishuzhibiao(xtxg, firsttitle);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            logger.Info("End job Tonghuashunxuangu");
        }