请问,如何时时抓取彩票开奖数据,我的程序用的是Access数据库,
比如:下面网页的数据,10分钟更新一次,如何抓取
http://www.500wan.com/static/public/ssc/txt/opencode/29.txt或者是:
http://jk.trade.500wan.com/ssc/
右边的开奖数据

解决方案 »

  1.   

    使用 WebClient 对象下载数据,并且自己分析,存入数据库。
      

  2.   

    第一个好办啊,就一个txt文档,你自己下载到本地,然后遍历txt中的每一行,将数据取出来,放到你的Access数据库中就可以了。第二个需要抓取网页源码,然后通过正则匹配数据,然后如你的Access数据库。http://blog.csdn.net/taomanman/article/details/6693594
      

  3.   

    第一步抓取:
    参考代码
    public static string HttpGetHtmlSource(string url, string encodingName, HttpMethod httpMethod, Dictionary<string, string> postData)
            {
                System.Text.Encoding encoding= System.Text.Encoding.GetEncoding(encodingName);
                System.Net.WebResponse response = GetWebReponse(url, httpMethod, postData, encoding);
                System.IO.Stream stream = response.GetResponseStream();
                System.IO.StreamReader reader = new System.IO.StreamReader(stream, encoding);
                string html = reader.ReadToEnd();
                stream.Close();
                reader.Close();
                response.Close();
                return html;
            }
    public static string HttpGetHtmlSource(string url, string encodingName, HttpMethod httpMethod, Dictionary<string, string> postData)
            {
                System.Text.Encoding encoding= System.Text.Encoding.GetEncoding(encodingName);
                System.Net.WebResponse response = GetWebReponse(url, httpMethod, postData, encoding);
                System.IO.Stream stream = response.GetResponseStream();
                System.IO.StreamReader reader = new System.IO.StreamReader(stream, encoding);
                string html = reader.ReadToEnd();
                stream.Close();
                reader.Close();
                response.Close();
                return html;
            }
    public static string GetHttpPostData(System.Text.Encoding encoding, Dictionary<string, string> postData)
            {
                if (postData == null || postData.Count < 1)
                {
                    return null;
                }
                StringBuilder sbData = new StringBuilder();
                foreach (var item in postData)
                {
                    sbData.AppendFormat("{0}={1}&", HttpUtility.UrlEncode(item.Key, encoding), HttpUtility.UrlEncode(item.Value, encoding));
                }
                if (sbData.Length > 0)
                {
                    sbData.Length = sbData.Length - 1;
                }
                return sbData.ToString();
            }
    第二部分析html代码
    要么直接字符串截取,要么正则。第三部分变化
    反正别人有变化,你也及时修改代码,
    可以做个job,定时把抓下来的对比,有变化,显示一个默认的,然后通知自己。
      

  4.   

    给你个类,你一看就知道了 http://www.netxk.cn/?p=78