Beispiel #1
0
        /// <summary>
        /// 企业安全人员证书
        /// </summary>
        /// <param name="info"></param>
        /// <param name="html"></param>
        protected void AddCorpSecLicStaff(CorpInfo info, string html)
        {
            Parser   parser   = new Parser(new Lexer(html));
            NodeList nodeList = parser.ExtractAllNodesThatMatch(new AndFilter(new TagNameFilter("div"), new HasAttributeFilter("id", "ryaq")));

            if (nodeList != null && nodeList.Count > 0)
            {
                parser = new Parser(new Lexer(nodeList.ToHtml().Replace("th", "td")));
                NodeList tableNode = parser.ExtractAllNodesThatMatch(new TagNameFilter("table"));
                if (tableNode != null && tableNode.Count > 0)
                {
                    TableTag table = tableNode[0] as TableTag;
                    for (int i = 1; i < table.RowCount; i++)
                    {
                        TableRow tr = table.Rows[i];
                        if (tr.Columns[0].ToPlainTextString().Contains("没有显示结果"))
                        {
                            break;
                        }

                        string PersonName = string.Empty, PersonCertNo = string.Empty, GrantUnit = string.Empty, GrantDate = string.Empty;

                        PersonName   = tr.Columns[1].ToNodePlainString();
                        PersonCertNo = tr.Columns[2].ToNodePlainString();
                        GrantUnit    = tr.Columns[3].ToNodePlainString();
                        GrantDate    = tr.Columns[4].ToPlainTextString().GetDateRegex();

                        CorpSecLicStaff SecLicStaff = ToolDb.GenCorpSecLicStaff(info.Id, PersonName, PersonCertNo, GrantUnit, GrantDate, info.Url);
                        ToolDb.SaveEntity(SecLicStaff, string.Empty);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 企业安全人员证书
        /// </summary>
        /// <param name="info"></param>
        /// <param name="html"></param>
        protected void AddCorpSecLicStaff(CorpInfo info, string param, string corpType)
        {
            string url = "http://portal.szjs.gov.cn:8888/publicShow/queryPersonSafe.html";

            string[]            postParams = new string[] { "param", "corpType", "orgCode", "page" };
            string[]            postValues = new string[] { param, corpType, info.CorpCode, "1" };
            NameValueCollection nvc        = ToolWeb.GetNameValueCollection(postParams, postValues);
            string html = string.Empty;

            try
            {
                html = ToolWeb.GetHtmlByUrl(url, nvc, Encoding.UTF8);
            }
            catch
            {
                Thread.Sleep(12 * 60 * 1000);
                try
                {
                    html = ToolWeb.GetHtmlByUrl(url, nvc, Encoding.UTF8);
                }
                catch
                {
                    Thread.Sleep(8 * 60 * 1000);
                    return;
                }
            }
            JavaScriptSerializer        java        = new JavaScriptSerializer();
            Dictionary <string, object> jsonResults = (Dictionary <string, object>)java.DeserializeObject(html);
            int pageInt = 1;

            try
            {
                pageInt = (int)jsonResults["totalPage"];
            }
            catch { }
            for (int i = 1; i <= pageInt; i++)
            {
                if (i > 1)
                {
                    postValues = new string[] { param, corpType, info.CorpCode, i.ToString() };
                    nvc        = ToolWeb.GetNameValueCollection(postParams, postValues);
                    try
                    {
                        html = ToolWeb.GetHtmlByUrl(url, nvc, Encoding.UTF8);
                    }
                    catch
                    {
                        Thread.Sleep(12 * 60 * 1000);
                        try
                        {
                            html = ToolWeb.GetHtmlByUrl(url, nvc, Encoding.UTF8);
                        }
                        catch
                        {
                            Thread.Sleep(8 * 60 * 1000);
                            continue;
                        }
                    }
                    jsonResults = (Dictionary <string, object>)java.DeserializeObject(html);
                }
                object[] dicRecords = (object[])jsonResults["records"];
                foreach (object dicRecord in dicRecords)
                {
                    string PersonName = string.Empty, PersonCertNo = string.Empty, GrantUnit = string.Empty, GrantDate = string.Empty;

                    Dictionary <string, object> dic = (Dictionary <string, object>)dicRecord;
                    PersonName   = Convert.ToString(dic["name"]);
                    PersonCertNo = Convert.ToString(dic["lics_id"]);
                    GrantUnit    = Convert.ToString(dic["issue_dept"]);
                    GrantDate    = Convert.ToString(dic["issue_date"]);

                    CorpSecLicStaff SecLicStaff     = ToolDb.GenCorpSecLicStaff(info.Id, PersonName, PersonCertNo, GrantUnit, GrantDate, info.Url);
                    ToolDb.SaveEntity(SecLicStaff, string.Empty);
                }
            }
        }