/// <summary> /// 历史成交明细 页数 /// http://market.finance.sina.com.cn/transHis.php?date=2017-10-13&symbol=sh600036 /// </summary> public int GetLSCJMXCount(string stockcode, string date) { string url = string.Format("http://market.finance.sina.com.cn/transHis.php?date={0}&symbol={1}", date, Convertor.AddStockCodePrefix(stockcode)); var httpdownloader = new HTTP(); var headers = new Dictionary <HttpRequestHeader, string>(); headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"); headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"); headers.Add(HttpRequestHeader.Host, "market.finance.sina.com.cn"); headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"); headers.Add(HttpRequestHeader.Cookie, "U_TRS1=000000bc.81346475.5a10967a.97e5dd54; U_TRS2=000000bc.813e6475.5a10967a.ecb434e5; FINANCE2=56e2a29d3a8fe026d3c022d0667dda04"); var strData = httpdownloader.GetGzip2(url, Encoding.GetEncoding("GBK"), headers); if (!strData.Contains("输入的代码有误或没有交易数据")) { var startIndex = strData.IndexOf("var detailPages=") + "var detailPages=".Length; var endIndex = strData.IndexOf("var detailDate ="); var subString = strData.Substring(startIndex, endIndex - startIndex); var array = subString.Replace(";", string.Empty).Replace("[[", string.Empty).Replace("]]", string.Empty).Replace("\r\n", string.Empty).Split(new string[] { "],[" }, StringSplitOptions.RemoveEmptyEntries); return(array.Length); } return(0); }
public static string GetDataFromHttpAgent(string url) { var httpDownloader = new HTTP(); var html = httpDownloader.GetGzip2(url, Encoding.UTF8); return(html); }
/// <summary> /// 获取大单页码数 /// </summary> /// <returns></returns> public int GetDaDanPageCount() { var httpDownloader = new HTTP(); var headers = new Dictionary <HttpRequestHeader, string>(); headers.Add(HttpRequestHeader.Accept, "*/*"); headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"); headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded"); headers.Add(HttpRequestHeader.Host, "vip.stock.finance.sina.com.cn"); headers.Add(HttpRequestHeader.Referer, "http://vip.stock.finance.sina.com.cn/quotes_service/view/cn_bill_all.php"); headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"); var volume = 100; ///一手 string pageCountUrl = string.Format("http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/CN_Bill.GetBillListCount?num=100&page=1363&sort=ticktime&asc=0&volume={0}&type=0", volume); //(new String("283802")) string pageCountText = httpDownloader.GetGzip2(pageCountUrl, Encoding.GetEncoding("GBK"), headers); var pageCount = 0; var pageSize = 100; if (pageCountText.Contains("(new String(")) { pageCountText = pageCountText.Replace("(new String(", string.Empty).Replace(")", string.Empty).Replace("\"", string.Empty).Trim('\0'); pageCount = (0 < int.Parse(pageCountText) % volume) ? int.Parse(pageCountText) / pageSize + 1 : int.Parse(pageCountText) / pageSize; } return(pageCount); }
/// <summary> /// 获取历史交易 /// </summary> /// <param name="stockcode"></param> /// <param name="year"></param> /// <param name="jidu"></param> /// <returns></returns> /// <example>view-source:http://vip.stock.finance.sina.com.cn/corp/go.php/vMS_MarketHistory/stockid/600617.phtml?year=2017&jidu=1</example> public string GetLSJY(string stockcode, int year, int jidu) { string url = string.Format("http://vip.stock.finance.sina.com.cn/corp/go.php/vMS_MarketHistory/stockid/{0}.phtml?year={1}&jidu={2}", stockcode, year, jidu); var httpdownloader = new HTTP(); var headers = new Dictionary <HttpRequestHeader, string>(); headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"); headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4"); headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"); headers.Add(HttpRequestHeader.Referer, url); var strData = httpdownloader.GetGzip2(url, Encoding.GetEncoding("GBK"), headers); return(strData); }
/// <summary> /// 下载指定股票的首页概览 /// </summary> /// <param name="stockcode">股票代码</param> /// <returns></returns> public string GetSYGL(string stockcode) { var httpdownloader = new HTTP(); var headers = new Dictionary <HttpRequestHeader, string>(); headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"); headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4"); headers.Add(HttpRequestHeader.Host, "stockpage.10jqka.com.cn"); headers.Add(HttpRequestHeader.Referer, "http://www.10jqka.com.cn/"); headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"); var url = string.Format("http://stockpage.10jqka.com.cn/{0}/", stockcode); var html = httpdownloader.GetGzip2(url, Encoding.UTF8, headers); return(html); }
/// <summary> /// 下载指定的新闻内容 /// </summary> /// <param name="articleUrl">http://news.10jqka.com.cn/20171129/c601825811.shtml</param> /// <param name="parentUrl">http://news.10jqka.com.cn/today_list/20171129/</param> /// <returns></returns> public string GetNewsArticle(string articleUrl, string parentUrl) { var httpdownloader = new HTTP(); var headers = new Dictionary <HttpRequestHeader, string>(); headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"); headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"); headers.Add(HttpRequestHeader.Host, "news.10jqka.com.cn"); headers.Add(HttpRequestHeader.Referer, parentUrl); headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"); var html = httpdownloader.GetGzip2(articleUrl, Encoding.GetEncoding("GBK"), headers); return(html); }
/// <summary> /// 获取板块概念 /// </summary> /// <param name="stockCode"></param> /// <returns></returns> public string GetBKGN(string stockCode) { var url = string.Format("http://vip.stock.finance.sina.com.cn/corp/go.php/vCI_CorpOtherInfo/stockid/{0}/menu_num/5.phtml", stockCode); var httpDownloader = new HTTP(); var headers = new Dictionary <HttpRequestHeader, string>(); headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"); headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"); headers.Add(HttpRequestHeader.Host, "vip.stock.finance.sina.com.cn"); headers.Add(HttpRequestHeader.Referer, string.Format("http://vip.stock.finance.sina.com.cn/corp/go.php/vCI_CorpXiangGuan/stockid/{0}.phtml", stockCode)); headers.Add(HttpRequestHeader.UserAgent, CONST.UserAgent); var strData = httpDownloader.GetGzip2(url, Encoding.GetEncoding("GBK"), headers); return(strData); }
/// <summary> /// 获取财务摘要 /// http://vip.stock.finance.sina.com.cn/corp/go.php/vFD_FinanceSummary/stockid/601888.phtml /// </summary> /// <param name="stockCode"></param> public string GetCWZY(string stockCode) { var url = string.Format("http://vip.stock.finance.sina.com.cn/corp/go.php/vFD_FinanceSummary/stockid/{0}.phtml", stockCode); var httpDownloader = new HTTP(); var headers = new Dictionary <HttpRequestHeader, string>(); headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"); headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"); headers.Add(HttpRequestHeader.Host, "money.finance.sina.com.cn"); headers.Add(HttpRequestHeader.Referer, string.Format("http://money.finance.sina.com.cn/corp/go.php/vFD_FinanceSummary/stockid/{0}/displaytype/4.phtml", stockCode)); headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0(Windows NT 10.0; Win64; x64) AppleWebKit/537.36(KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"); var strData = httpDownloader.GetGzip2(url, Encoding.GetEncoding("GBK"), headers); return(strData); }
/// <summary> /// 获取日线数据 /// </summary> public string GetKLine(string stockCode) { var httpdownloader = new HTTP(); var url = string.Format("http://flashdata2.jrj.com.cn/history/js/share/{0}/other/dayk_ex.js?random=1510076545082", stockCode); var headers = new Dictionary <HttpRequestHeader, string>(); headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"); headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4"); headers.Add(HttpRequestHeader.Accept, "*/*"); headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); headers.Add(HttpRequestHeader.Referer, string.Format("http://stock.jrj.com.cn/share,{0}.shtml", stockCode)); headers.Add(HttpRequestHeader.Cookie, "vjuids=-492f73280.15ef65296f7.0.ba8d7db09d1c2; bdshare_firstime=1508740094204; jrj_uid=1508741900394rUUgyFVcaF; Hm_lvt_1d0c58faa95e2f029024e79565404408=1508777391,1508807313,1509945290,1509994113; ADVS=35a84227fd0d6c; ASL=17480,ancbu,6f1256096f1256d06f1256746f1256b36f1256e9; jrj_z3_newsid=2096; jrj_z3_home_newsid=2096; Hm_lvt_0359dbaa540096117a1ec782fff9c43f=1509949335,1509950934,1510076377,1510317592; Hm_lpvt_0359dbaa540096117a1ec782fff9c43f=1510317592; JRJ_Click_Track=171110204004%3Bhttp%3A//www.jrj.com.cn/%3B%3B%3B; WT_FPC=id=20aa92fff4d755ceb821508740094103:lv=1510317607242:ss=1510317607242; channelCode=3763BEXX; ylbcode=24S2AZ96; vjlast=1507371161.1510317592.11; ADVC=3599e935b514c4; Hm_lvt_d654909655f2581e69361531a7850450=1509994114,1509994127,1510076527,1510317608; Hm_lpvt_d654909655f2581e69361531a7850450=1510317608; JRJ_TODAYREAD_SHARE_COOKIE=%2C600330-2017-11-10-0; JRJ_LASTEST_SHARE_COOKIE=600330%2C300676%2C601388%2C600887%2C603533%2C603535"); var strData = httpdownloader.GetGzip2(url, Encoding.GetEncoding("GBK"), headers); return(strData); }
/// <summary> /// 历史成交明细 /// http://vip.stock.finance.sina.com.cn/quotes_service/view/vMS_tradehistory.php?symbol=sh600036&date=2017-10-13 /// </summary> /// <param name="stockcode">类似于 sz300668</param> /// <param name="date"></param> /// <param name="pageNumber"></param> /// <returns></returns> public string GetLSCJMX(string stockcode, string date, int pageNumber) { string url = string.Format("http://vip.stock.finance.sina.com.cn/quotes_service/view/vMS_tradehistory.php?symbol={0}&date={1}&page={2}", Convertor.AddStockCodePrefix(stockcode), date, pageNumber); var httpdownloader = new HTTP(); var headers = new Dictionary <HttpRequestHeader, string>(); headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"); headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"); headers.Add(HttpRequestHeader.Host, "vip.stock.finance.sina.com.cn"); headers.Add(HttpRequestHeader.Referer, string.Format("http://vip.stock.finance.sina.com.cn/quotes_service/view/vMS_tradehistory.php?symbol={0}&date={1}", stockcode, date)); headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"); headers.Add(HttpRequestHeader.Cookie, "vjuids=-3d20ba9f8.150715b95a8.0.9e4d081a; SGUID=1445010838969_24869349; U_TRS1=00000077.eff21405.56211d98.e270c652; SCF=AiNSdX-kSf4x3r5s3OPpIKeILKce6Ob9lRa-jJt11Vh5r8kMpPU24v_1hNWF-ZDmw1aBetJmtrTPFQDDGaqUuMU.; SINAGLOBAL=123.138.24.104_1468410916.956202; sso_info=v02m6alo5qztKWRk5iljpSMpZCToKWRk5SlkJSQpY6TgKWRk5iljpSQpY6ElLGOk6SziaeVqZmDtLKNs4C2jJOct4yTlLA=; visited_uss=gb_wb; UOR=,,; SR_SEL=1_511; lxlrtst=1509781793_o; close_left_xraytg=1; "); var strData = httpdownloader.GetGzip2(url, Encoding.GetEncoding("GBK"), headers); return(strData); }
/// <summary> /// 获取大单数据 /// </summary> /// <param name="pageIndex"></param> /// <param name="volume"></param> /// <returns></returns> public string GetDaDan(object pageIndex) { int volume = 100; var httpDownloader = new HTTP(); var headers = new Dictionary <HttpRequestHeader, string>(); headers.Add(HttpRequestHeader.Accept, "*/*"); headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"); headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded"); headers.Add(HttpRequestHeader.Host, "vip.stock.finance.sina.com.cn"); headers.Add(HttpRequestHeader.Referer, "http://vip.stock.finance.sina.com.cn/quotes_service/view/cn_bill_all.php"); headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"); var url = string.Format("http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/CN_Bill.GetBillList?num=100&page={0}&sort=ticktime&asc=0&volume={1}&type=0", pageIndex, volume); var pageContent = httpDownloader.GetGzip2(url, Encoding.GetEncoding("GBK"), headers); return(pageContent); }
/// <summary> /// SINA 融资融券 /// </summary> /// <returns></returns> public string GetRZRQ(string stockCode) { var symbol = Convertor.AddStockCodePrefix(stockCode); var startDate = string.Format("{0}-01-01", DateTime.Now.Year); var endDate = string.Format("{0:yyyy-MM-dd}", DateTime.Now); var url = string.Format("http://vip.stock.finance.sina.com.cn/q/go.php/vInvestConsult/kind/rzrq/index.phtml?symbol={0}&bdate={1}&edate={2}", symbol, startDate, endDate); var httpDownloader = new HTTP(); var headers = new Dictionary <HttpRequestHeader, string>(); headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"); headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"); headers.Add(HttpRequestHeader.Host, "vip.stock.finance.sina.com.cn"); headers.Add(HttpRequestHeader.UserAgent, CONST.UserAgent); var strData = httpDownloader.GetGzip2(url, Encoding.GetEncoding("GBK"), headers); return(strData); }
/// <summary> /// 获取指定日期的新闻列表 /// </summary> /// <param name="dateTime">格式:20171129</param> /// <returns></returns> public string GetNewsListCJYW(DateTime dateTime) { var httpdownloader = new HTTP(); string url = string.Format("http://news.10jqka.com.cn/today_list/{0}/", string.Format("{0:yyyyMMdd}", dateTime)); var headers = new Dictionary <HttpRequestHeader, string>(); headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"); headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"); headers.Add(HttpRequestHeader.Host, "news.10jqka.com.cn"); headers.Add(HttpRequestHeader.Referer, "http://news.10jqka.com.cn/today_list/"); headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"); var html = httpdownloader.GetGzip2(url, Encoding.GetEncoding("GBK"), headers); if (string.IsNullOrWhiteSpace(html)) { } return(html); }
/// <summary> /// 获取节日信息 /// </summary> /// <param name="year"></param> /// <returns></returns> public List <Dictionary <string, object> > GetHolidayArrangement() { var year = DateTime.Now.Year; var res = new List <Dictionary <string, object> >(); var url = "https://www.so.com/s?q=" + year + "+%E6%94%BE%E5%81%87%E5%AE%89%E6%8E%92"; var httpdownloader = new HTTP(); var headers = new Dictionary <HttpRequestHeader, string>(); headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"); headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br"); headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"); headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"); headers.Add(HttpRequestHeader.Host, "www.so.com"); var html = httpdownloader.GetGzip2(url, Encoding.UTF8, headers); var tbodyIndex1 = html.IndexOf("<tbody>") + "<tbody>".Length; var tbodyIndex2 = html.IndexOf("</tbody>") - html.IndexOf("<tbody>") - "</tbody>".Length + 1; var trArray = html.Substring(tbodyIndex1, tbodyIndex2).Replace("</tr><tr>", ";").Split(new char[] { ';' }); foreach (var tr in trArray) { //<tr>< td class="mh-col mh-col0"><span class="mh-txt">元旦</span></td><td class="mh-col mh-col1"><span class="mh-txt">12月30日 ~1月1日</span></td><td class="mh-col mh-col2"><span class="mh-txt">1月1日(周一)补休</span></td><td class="mh-col mh-col3 mh-col-last"><span class="mh-txt">共3天</span></td> var temp1 = tr.Replace("<br>", " ").Replace("<tr>", string.Empty).Replace("\"", string.Empty).Replace("<span class=mh-txt>", string.Empty).Replace("</span>", string.Empty) .Replace("mh-col0", string.Empty).Replace("mh-col1", string.Empty).Replace("mh-col2", string.Empty).Replace("mh-col3", string.Empty).Replace("mh-col-last", string.Empty).Replace("mh-col", string.Empty).Replace("class=", string.Empty) .Replace("<td", string.Empty).Replace("</td>", ";").Replace(">", string.Empty).Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); var item = new Dictionary <string, object>(); var temp2 = year + "/" + temp1[1].Trim().Split(new char[] { '~' })[0].Replace("月", "/").Replace("日", string.Empty); var temp3 = year + "/" + temp1[1].Trim().Split(new char[] { '~' })[1].Replace("月", "/").Replace("日", string.Empty); temp2 = (temp2.Contains("(")) ? temp2.Substring(0, temp2.IndexOf("(")) : temp2; temp3 = (temp3.Contains("(")) ? temp3.Substring(0, temp3.IndexOf("(")) : temp3; item["节日"] = temp1[0].Trim(); item["放假开始时间"] = Convert.ToDateTime(temp2); item["放假结束时间"] = Convert.ToDateTime(temp3); item["调休上班时间"] = temp1[2].Trim(); item["放假天数"] = Convert.ToInt32(temp1[3].Trim().Replace("共", string.Empty).Replace("天", string.Empty)); res.Add(item); } return(res); }
/// <summary> /// 股市雷达 用于发现异常股票 /// http://finance.sina.com.cn/stockradar/stockradar16.html /// </summary> /// <returns></returns> public List <string> GetStockRadar() { var list = new List <string>(); for (int k = 1; k <= 16; k++) { var url = string.Format("http://finance.sina.com.cn/stockradar/stockradar{0}.html", k); var httpDownloader = new HTTP(); var headers = new Dictionary <HttpRequestHeader, string>(); headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"); headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"); headers.Add(HttpRequestHeader.Host, "finance.sina.com.cn"); headers.Add(HttpRequestHeader.Referer, string.Format("http://finance.sina.com.cn/stockradar/stockradar{0}.html", (k % 14) + 2)); headers.Add(HttpRequestHeader.UserAgent, CONST.UserAgent); var strData = httpDownloader.GetGzip2(url, Encoding.GetEncoding("GBK"), headers); list.Add(strData); LOGGER.Log(string.Format("正在获取 股市雷达 {0}", k)); ThreadManager.Pause(seconds: 5); } return(list); }
/// <summary> /// 下载每个股票的页面 UTF8 /// </summary> public void GetPageKLine() { this.GetALLStockCode(); ///准备所有股票代码 var queueUrl = new Queue <KeyValuePair <string, string> >(); var httpdownloader = new HTTP(Encoding.UTF8); httpdownloader.EventException += (object sender, EventArgs e) => { var ee = e as EventProcEventArgs; Console.WriteLine("下载失败 {0}", ee.Default); var item = ee.Default as Dictionary <string, object>; item["ContentType"] = "个股日线页面下载失败异常信息"; item["TaskID"] = THS.CONST.TaskID; var url = item["Url"].ToString(); var type = string.Empty; mongo.Save(THS.CONST.DBName, THS.CONST.Exception, item); #region 类型判断 if (url.Contains("/01/last.js")) { type = "日线数据"; } #endregion queueUrl.Enqueue(new KeyValuePair <string, string>(type, url)); Thread.Sleep(60 * 1000); }; if (null != this.stockCodeDict) { foreach (var item in this.stockCodeDict) { queueUrl.Enqueue(new KeyValuePair <string, string>(item.Key.Trim(), item.Value.Trim()));///Key:StockCode Value:StockName } } while (0 < queueUrl.Count) { var queueItem = queueUrl.Dequeue(); { var urlList = new List <KeyValuePair <string, string> >(); urlList.Add(new KeyValuePair <string, string>("日线数据", string.Format("http://d.10jqka.com.cn/v2/line/hs_{0}/01/last.js", queueItem.Key))); ///日线数据 foreach (var url in urlList) { var headers = new Dictionary <HttpRequestHeader, string>(); headers.Add(HttpRequestHeader.Accept, "*/*"); headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.8,en;q=0.4"); headers.Add(HttpRequestHeader.Host, "d.10jqka.com.cn"); headers.Add(HttpRequestHeader.Referer, "http://data.10jqka.com.cn/funds/ggzjl/"); headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"); headers.Add(HttpRequestHeader.Cookie, "_ga=GA1.3.1308637288.1480656705; Hm_lvt_f79b64788a4e377c608617fba4c736e2=1490269470; searchGuide=sg; spversion=20130314; __utma=156575163.1308637288.1480656705.1500515050.1510209522.23; __utmz=156575163.1510209522.23.17.utmcsr=10jqka.com.cn|utmccn=(referral)|utmcmd=referral|utmcct=/; Hm_lvt_78c58f01938e4d85eaf619eae71b4ed1=1509994430,1510022996,1510068180,1510300758; historystock=300201%7C*%7C601989%7C*%7C002156%7C*%7C600807; log=; v=AfoYrKP4d7j2x_gcqfWa-6RZSysYq39G8C3yOgTzpzFYPpSd7DvOlcC_QirU"); var html = httpdownloader.GetGzip2(url.Value, Encoding.GetEncoding("GBK"), headers); var item = new { StockCode = queueItem.Key, StockName = queueItem.Value, ContentType = url.Key, Url = url.Value, CreatTime = DateTime.Now, Page = html, MD5 = Convertor.Encode_MD5(html), TaskID = THS.CONST.TaskID }; var collectionName = THS.CONST.PageKLine; mongo.Save(THS.CONST.DBName, collectionName, item); Console.WriteLine("已保存 " + url.Key + " " + url.Value); Thread.Sleep(1000); } } } }