Beispiel #1
0
        /// <summary>
        /// 插入数据库
        /// </summary>
        /// <param name="strLoginUrl"></param>
        /// <param name="strTargerUrl"></param>
        /// <param name="data">列表数据</param>
        public void InsertDataHGZPool(string strTargerUrl, DataTable data, int page)
        {
            LogWrite(string.Format("{0} 合格证详细信息正在抓取第{1}页,共{2}条数据", DateTime.Now.ToString("G"), (page).ToString(), data.Rows.Count.ToString()));
            DetailInfo detailInfo = new DetailInfo();
            string     strContex  = string.Empty;
            string     msg        = string.Empty;
            int        dataCount  = data.Rows.Count;

            insertHGZ.InsertListHGZ(data);
            dtInsert = convertHGZ.getDetailsHGZTable();
            int i = 1;

            try
            {
                if (IsStopped)
                {
                    for (i = 0; i < dataCount; i++)
                    {
                        detailInfo           = new DetailInfo();
                        detailInfo.SQBH      = data.Rows[i]["SQBH"].ToString().Trim();
                        detailInfo.APP_TIME  = data.Rows[i]["APP_TIME"].ToString().Trim();
                        detailInfo.APP_TYPE  = data.Rows[i]["APP_TYPE"].ToString().Trim();
                        detailInfo.TargerUrl = strTargerUrl;
                        insertQueue.Push(detailInfo);
                    }

                    iThread_ready = 0;                                                        //线程数重置为0
                    Thread thAutoCrawlerDetail1;
                    thAutoCrawlerDetail1 = new Thread(new ThreadStart(InsertDataHGZDetails)); //获取线程1
                    thAutoCrawlerDetail1.IsBackground = true;
                    thAutoCrawlerDetail1.Start();

                    Thread thAutoCrawlerDetail2;
                    thAutoCrawlerDetail2 = new Thread(new ThreadStart(InsertDataHGZDetails));  //获取线程2
                    thAutoCrawlerDetail2.IsBackground = true;
                    thAutoCrawlerDetail2.Start();

                    Thread thAutoCrawlerDetail3;
                    thAutoCrawlerDetail3 = new Thread(new ThreadStart(InsertDataHGZDetails));  //获取线程3
                    thAutoCrawlerDetail3.IsBackground = true;
                    thAutoCrawlerDetail3.Start();

                    while (iThread_ready < 3)
                    {
                        Thread.Sleep(1000 * 2);//等待2秒
                    }
                }
                if (IsStopped)
                {
                    insertHGZ.InsertDBHGZ(dtInsert);
                    LogWrite(string.Format("{0} 合格证详细信息插入第{1}页,共{2}条数据", DateTime.Now.ToString("G"), (page).ToString(), dtInsert.Rows.Count.ToString()));
                }
            }
            catch (Exception ex)
            {
                msg = string.Format("{0} 合格证详细信息正在抓取第{1}页,插入合格证详细信息数据时出错:i={2},{3}", DateTime.Now.ToString("G"), page.ToString(), i.ToString(), ex.Message);
                LogWrite(msg);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 机动车合格证申请界面-详细信息
        /// </summary>
        public void GetHtmlSourceDetailsHGZ(string appTime, string appType, string strTargerUrl)
        {
            string     strContex  = ReadHTML(strTargerUrl);
            ConvertHGZ convertHGZ = new ConvertHGZ();
            //var data = convertHGZ.getDetailsHGZ(strContex);
            var       data1     = convertHGZ.getDetailsHGZ(appTime, appType, strContex);
            InsertHGZ insertHGZ = new InsertHGZ();

            //insertHGZ.InsertDetailsHGZ(data);
            insertHGZ.InsertDBHGZ(data1);
            //insertHGZ.InsertSingleDBHGZ(data1);
            //insertHGZ.InsertTvpDBHGZ(data1);
        }
Beispiel #3
0
        /// <summary>
        /// 插入数据库
        /// </summary>
        /// <param name="strLoginUrl"></param>
        /// <param name="strTargerUrl"></param>
        /// <param name="data">列表数据</param>
        public void InsertDataHGZ(string strTargerUrl, DataTable data, int page)
        {
            LogWrite(string.Format("{0} 正在抓取合格证详细信息第{1}页,共{2}条数据", DateTime.Now.ToString("G"), (page).ToString(), data.Rows.Count.ToString()));

            string     strContex  = string.Empty;
            string     msg        = string.Empty;
            int        dataCount  = data.Rows.Count;
            InsertHGZ  insertHGZ  = new InsertHGZ();
            ConvertHGZ convertHGZ = new ConvertHGZ();

            insertHGZ.InsertListHGZ(data);
            DataTable dtInsert = new DataTable();
            int       i        = 0;

            try
            {
                for (i = 0; i < dataCount; i++)
                {
                    if (IsStopped)
                    {
                        string id       = data.Rows[i]["SQBH"].ToString().Trim();
                        string app_time = data.Rows[i]["APP_TIME"].ToString().Trim();
                        string app_type = data.Rows[i]["APP_TYPE"].ToString().Trim();

                        string strContent = Tool.ReadHTML(strTargerUrl + id);
                        if (!string.IsNullOrEmpty(strContent))
                        {
                            var dataDetails = convertHGZ.getDetailsHGZ(app_time, app_type, strContent);
                            //try
                            //{
                            //    insertHGZ.InsertDBHGZ(dataDetails);
                            //}
                            //catch (ArgumentException ex)
                            //{
                            //    msg = string.Format("{0} 正在抓取第{1}页,插入合格证详细信息数据时出错:i={2},id={3},{4}", DateTime.Now.ToString("G"), page.ToString(), i.ToString(),id, ex.InnerException.Message);
                            //    LogWrite(msg);
                            //}
                            if (i == 0)
                            {
                                dtInsert = dataDetails;
                            }
                            else
                            {
                                DataRow dr = dataDetails.Rows[0];
                                dtInsert.Rows.Add(dr.ItemArray);
                            }
                        }
                    }
                }
                if (IsStopped)
                {
                    insertHGZ.InsertDBHGZ(dtInsert);
                    LogWrite(string.Format("{0} 插入合格证详细信息第{1}页,共{2}条数据", DateTime.Now.ToString("G"), (page).ToString(), dtInsert.Rows.Count.ToString()));
                }
            }
            catch (ArgumentException ex)
            {
                msg = string.Format("{0} 正在抓取第{1}页,插入合格证详细信息数据时出错:i={2},{3}", DateTime.Now.ToString("G"), page.ToString(), i.ToString(), ex.InnerException.Message);
                LogWrite(msg);
            }
            //msg = string.Format("{0} 正在抓取第{1}页,插入详细信息{2}条数据", DateTime.Now.ToString("G"), page.ToString(), dataCount.ToString());
            //LogWrite(msg);
        }