protected void bntInterfaceAdd_Click(object sender, EventArgs e)
 {
     if (ddlInterfaceType.SelectedItem.Value == "-1")
     {
         ddlInterfaceType.Focus();
         return;
     }
     if (txtInterfaceUrl.Text.Equals("")
         ||txtInterfaceName.Text.Equals("")
         ||txtInterfaceBody.Text.Equals("")
         ||txtInterfaceSource.Text.Equals("")
         ||txtInterfaceSourceUrl.Text.Equals(""))
     {
         return;
     }
     CnInterfaceInfo cnf = new CnInterfaceInfo();
     cnf.CnInterfaceTypeID = Convert.ToInt32(ddlInterfaceType.SelectedItem.Value);
     cnf.CnInterfaceAppearTime = Convert.ToDateTime(txtInterfaceAppearTime.Text);
     cnf.CnInterfaceName = txtInterfaceName.Text;
     cnf.CnInterfaceUrl = txtInterfaceUrl.Text;
     cnf.CnInterfacebody = txtInterfaceBody.Text;
     cnf.CnInterfaceSource = txtInterfaceSource.Text;
     cnf.CnInterfaceSourceUrl = txtInterfaceSourceUrl.Text;
     InterfaceInfo IFI = new InterfaceInfo();
     int insertcount = IFI.InsertCnInterfaceInfo(cnf);
     Response.Write(insertcount.ToString());
 }
Example #2
0
 protected void GetCnInterfaceNames(string name)
 {
     InterfaceInfo ifi = new InterfaceInfo();
     DataSet ds=ifi.GetCnInterfaceNames(name);
     if (ds != null && ds.Tables[0].Rows.Count>0)
     {
         StringBuilder sb = new StringBuilder();
         sb.Append("<table  border=\"0\" cellpadding =\"1\" cellspacing =\"0\" width=\"100%\"> ");
         for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
         {
             sb.Append("<tr  style='cursor:hand'  id='TrNumber" + i.ToString() + "' onmouseover='trOnmouseOver(this.id);' onmouseout='trOnmouseOut(this.id);'  >");
             sb.Append("<td id='TdNumber" + i.ToString() + "' onclick='tdOnclick(this.id);'><font size=2 color=#666699>" + ds.Tables[0].Rows[i]["CnInterfaceName"].ToString().Replace(name, "<font color=#006a00>" + name + "</font>") + "</font></td>");
             sb.Append("</tr>");
         }
         sb.Append("</table><input type=\"hidden\" id=\"hiddennamecount\" value=\"" + ds.Tables[0].Rows.Count .ToString()+ "\">");
         Response.Write(sb.ToString());
         Response.Flush();
         Response.End();
     }
     else
     {
         Response.Write("0");
         Response.Flush();
         Response.End();
     }
 }
Example #3
0
        /// <summary>
        /// 通过URL获取接口对象.
        /// </summary>
        /// <param name="wc">WebClient 对象.</param>
        /// <param name="url">接口列表URL.</param>
        /// <param name="cnurlxp">接口地址(XPath).</param>
        /// <param name="cnurlRgx">接口地址正则表达式(Regex).</param>
        /// <param name="cnnamexp">接口名称(XPath).</param>
        /// <param name="cnnameRgx">接口名称正则表达式(Regex)</param>
        /// <param name="cnbodyXp">接口内容(XPath).</param>
        /// <param name="cnbodyRgx">接口内容正则表达式(Regex).</param>
        /// <param name="cntimeXp">接口发布时间(XPath).</param>
        /// <param name="cntimeRgx">接口发布时间正则表达式(Regex).</param>
        /// <param name="cntimeF">接口发布时间Format.</param>
        /// <param name="cnsource">接口网络来源.</param>
        /// <param name="cnsourceurl">接口网络来源地址.</param>
        /// <returns>接口对象.</returns>
        public static int GetCnInterfaceInfoEntity(WebClient wc,
                                                                                              string url,
                                                                                              string cnurlxp,
                                                                                              string cnurlRgx,
                                                                                              string cnnamexp,
                                                                                              string cnnameRgx,
                                                                                              string cnbodyXp,
                                                                                              string cnbodyRgx,
                                                                                              string cntimeXp,
                                                                                              string cntimeRgx,
                                                                                              string cntimeF,
                                                                                              string cnsource,
                                                                                              string cnsourceurl,
                                                                                              int cntypeid,
                                                                                              int sourceno,
                                                                                              int pagesize)
        {
            var html = wc.DownloadString(url);
            var doc = new HtmlDocument();
            doc.LoadHtml(html);

            int insertcount = 0;
            for (int i = 1; i <=pagesize; i++)
            {
                try
                {
                    //xpath处理
                    string urlllog = "";
                    if (sourceno == 1)
                    {
                        cnurlxp = cnurlxp.Replace("cnface", (i * 2).ToString());
                        cnnamexp = cnnamexp.Replace("cnface", (i * 2).ToString());
                        cnbodyXp = cnbodyXp.Replace("cnface", i.ToString());
                        cntimeXp = cntimeXp.Replace("cnface", (i * 3).ToString());
                    }
                    if (sourceno == 2)
                    {
                        cnurlxp = cnurlxp.Replace("cnface", i.ToString());
                        cnnamexp = cnnamexp.Replace("cnface", i.ToString());
                        cnbodyXp = cnbodyXp.Replace("cnface", i.ToString());
                        cntimeXp = cntimeXp.Replace("cnface", i.ToString());
                        urlllog = "http://www.skycn.com/";
                    }
                    //取接口地址
                    var cnurl = urlllog + doc.DocumentNode.SelectSingleNode(cnurlxp).Attributes["href"].Value;
                    if (cnurlRgx != null && !cnurlRgx.Equals(""))
                        cnurl = new Regex(cnurlRgx).Match(cnurl).Groups[1].Value;
                    //取接口名称
                    var title = doc.DocumentNode.SelectSingleNode(cnnamexp).InnerHtml;
                    if (cnnameRgx != null && !cnnameRgx.Equals(""))
                        title = new Regex(cnnameRgx).Match(title).Groups[1].Value;
                    title = new HtmlToText().ConvertHtml(title).Trim();
                    //取接口内容
                    var body = doc.DocumentNode.SelectSingleNode(cnbodyXp).InnerHtml;
                    if (cnbodyRgx != null && !cnbodyRgx.Equals(""))
                        title = new Regex(cnbodyRgx).Match(body).Groups[1].Value;
                    body = new HtmlToText().ConvertHtml(body).Trim();

                    //取接口发布时间
                    var ptStr = doc.DocumentNode.SelectSingleNode(cntimeXp).InnerHtml;
                    if (cntimeRgx != null && !cntimeRgx.Equals(""))
                        ptStr = new Regex(cntimeRgx).Match(ptStr).Groups[1].Value;

                    CnInterfaceInfo cnf = new CnInterfaceInfo
                    {
                        CnInterfaceTypeID = cntypeid,
                        CnInterfaceName = title,
                        CnInterfacebody = body,
                        CnInterfaceUrl = cnurl,
                        CnInterfaceSource = cnsource,
                        CnInterfaceSourceUrl = cnsourceurl,
                        CnInterfaceAppearTime = Convert.ToDateTime(ptStr)
                    };
                    InterfaceInfo IFI = new InterfaceInfo();
                    int cont= IFI.InsertCnInterfaceInfo(cnf);
                    if (cont > 0)
                        insertcount += cont;
                }
                catch { continue; }
                System.Threading.Thread.Sleep(200);
            }
            return insertcount;
        }
Example #4
0
        /// <summary>
        /// 获取有道接口查询结果
        /// </summary>
        /// <param name="html">网络地址</param>
        /// <returns>有道查询结果</returns>
        public static int GetCnInterfaceInfoFromYoudao(string url)
        {
            int insertcount = 0;

            WebClient wc = new WebClient
            {
                Encoding = Encoding.GetEncoding("gb2312")
            };
            string html = wc.DownloadString(url.Trim());

            //string html = "";
            //System.IO.StreamReader sr = new System.IO.StreamReader("D:\\CnInterface\\CnWeb\\html\\youdaocode.txt", Encoding.GetEncoding("gb2312"));
            //lock (sr)
            //{
            //    html = sr.ReadToEnd();
            //    sr.Close();
            //}

            var doc = new HtmlDocument();
            doc.LoadHtml(html);
            string nameValue = "";
            string urlValue = "";
            string bodyValue = "";
            string timeValue = "";
            //StringBuilder sb = new StringBuilder();
            for (int i = 1; i <= 10; i++)
            {
                try
                {
                    string nameXpath = "/body[1]/div[6]/div[2]/ul[1]/li["+i.ToString()+"]/h3[1]/a[1]";
                    string urlXpath = "/body[1]/div[6]/div[2]/ul[1]/li[" + i.ToString() + "]/h3[1]/a[1]/@href[1]";
                    string bodyXpath = "/body[1]/div[6]/div[2]/ul[1]/li[" + i.ToString() + "]/div[1]";
                    string timeXpath = "/body[1]/div[6]/div[2]/ul[1]/li[" + i.ToString() + "]/p[1]/span[1]";

                    nameValue = doc.DocumentNode.SelectSingleNode(nameXpath).InnerText;
                    nameValue = new HtmlToText().ConvertHtml(nameValue).Trim();
                    urlValue = doc.DocumentNode.SelectSingleNode(urlXpath).Attributes["href"].Value;
                    try
                    {
                        bodyValue = doc.DocumentNode.SelectSingleNode(bodyXpath).InnerHtml;
                        bodyValue = new HtmlToText().ConvertHtml(bodyValue).Trim();
                    }
                    catch
                    {
                        bodyValue = "";
                    }
                    try
                    {
                        timeValue = doc.DocumentNode.SelectSingleNode(timeXpath).InnerText;
                        timeValue = timeValue.Substring(timeValue.LastIndexOf("20")).Replace("-->", "");
                    }
                    catch
                    {
                        timeValue = "";
                    }

                    //sb.Append(" <div style=\"margin-top: 20px; margin-bottom: 20px; width:678px\">");
                    //sb.Append(" <div>");
                    //sb.Append(" <a target=\"_blank\"  href=\"" + urlValue + "\"><font color=blue>" + nameValue.Replace("接口", "<font color=red>接口</font>") + "</font></a>");
                    //sb.Append(" </div>");
                    //sb.Append(" <div style=\"font-size: 13px;\">");
                    //sb.Append(" <font size=2 >" + bodyValue.Replace("接口", "<font color=red>接口</font>") + "</font>");
                    //sb.Append(" </div>");
                    //sb.Append(" <div>");
                    //sb.Append(" <font color=#006600>" + urlValue + "</font>&nbsp;&nbsp;<font size=2 color=#006600>" + timeValue + "</font>&nbsp;&nbsp;<a target=\"_blank\" href=\"" + url + "\"><font size=2  color=#666699>有道搜索</font></a>");
                    //sb.Append("  </div>");
                    //sb.Append(" </div>");
                }
                catch
                {
                    continue;
                }

                try
                {
                    DateTime dt = Convert.ToDateTime(timeValue);
                }
                catch
                {
                    timeValue = DateTime.Now.ToString("yyyy-MM-dd");
                }
                CnInterfaceInfo cnf = new CnInterfaceInfo
                {
                    CnInterfaceTypeID = 2,
                    CnInterfaceName = nameValue,
                    CnInterfacebody = bodyValue,
                    CnInterfaceUrl = urlValue,
                    CnInterfaceSource = "有道搜索",
                    CnInterfaceSourceUrl = url,
                    CnInterfaceAppearTime = Convert.ToDateTime(timeValue)
                };
                InterfaceInfo IFI = new InterfaceInfo();
                int cont = IFI.InsertCnInterfaceInfo(cnf);
                if (cont > 0)
                    insertcount++;

                System.Threading.Thread.Sleep(200);
            }

            return insertcount;
        }
 private string SelectInterfaceListInfo(int ttype,string searchStr, int pagesize, int pageindex,out int totalcount,out int totalpage)
 {
     string returnString = "";
      try
      {
          InterfaceInfo IFI = new InterfaceInfo();
          IList<CnInterfaceInfo> ICII = IFI.GetCnInterfaceInfoByName(ttype,searchStr, pagesize, pageindex, out totalcount, out totalpage);
          if (ICII != null)
          {
              SearchResultCount = totalcount.ToString();
              StringBuilder sb = new StringBuilder();
              foreach (CnInterfaceInfo icii in ICII)
              {
                  sb.Append(" <div style=\"margin-top: 20px; margin-bottom: 20px;\">");
                  sb.Append(" <div>");
                  sb.Append(" <a target=\"_blank\"  href=\"" + icii.CnInterfaceUrl + "\"><font color=blue>" + WordFiter(icii.CnInterfaceName.Replace(searchStr, "<font color=red>" + searchStr + "</font>")) + "</font></a>");
                  sb.Append(" </div>");
                  sb.Append(" <div style=\"font-size: 13px;\">");
                  sb.Append(" <font size=2 >" + WordFiter(icii.CnInterfacebody.Replace(searchStr, "<font color=red>" + searchStr + "</font>")) + "</font>");
                  sb.Append(" </div>");
                  sb.Append(" <div>");
                  sb.Append(" <font color=#006600>" + (icii.CnInterfaceUrl.Length > 66 ? icii.CnInterfaceUrl.Substring(0, 66) : icii.CnInterfaceUrl) + "</font>&nbsp;&nbsp;<font size=2 color=#006600>" + icii.CnInterfaceAppearTime.ToString("yyyy-MM-dd") + "</font>&nbsp;&nbsp;<a target=\"_blank\" href=\"" + icii.CnInterfaceSourceUrl + "\"><font size=2  color=#666699>" + icii.CnInterfaceSource + "</font></a>");
                  sb.Append("  </div>");
                  sb.Append(" </div>");
              }
              if (totalpage > 1)
              {
                  string parame = "";
                  sb.Append("<table  border=\"0\" cellpadding =\"4\" cellspacing =\"0\" width=\"888px\">");
                  sb.Append("<tr >");
                  sb.Append("<td>");
                  if (pageindex > 1)
                  {
                      parame = "SelectResult.aspx?t=" + GetTypaNameByNum(ttype) + "&p=" + (pageindex - 1).ToString() + "&s=" + Server.HtmlEncode(searchStr);
                      sb.Append("<a  href=\"" + parame + "\"><font color=\"blue\">上一页</font></a><img border=\"0\"  src=\"img/blank001.jpg\" width=\"8px\"   style=\"FILTER: alpha(opacity=0);opacity:0;\"/>");
                  }
                  int beginindex = 1;//循环开始index
                  int endindex = totalpage;//循环结束index
                  if (totalpage > 20 && pageindex > 11 && totalpage - pageindex > 8)
                  {
                      beginindex = pageindex - 10;
                  }
                  if (totalpage > 20 && pageindex > 11 && totalpage - pageindex < 9)
                  {
                      beginindex = pageindex - (20 - (totalpage - pageindex) - 1);
                  }
                  if (endindex > 10)
                  {
                      endindex = pageindex + 9;
                      if (endindex > totalpage)
                      {
                          endindex = totalpage;
                      }
                  }
                  for (int i = beginindex; i <= endindex; i++)
                  {
                      if ((i) == pageindex)
                      {
                          sb.Append("<img border=\"0\"  src=\"img/blank001.jpg\" width=\"3px\"   style=\"FILTER: alpha(opacity=0);opacity:0;\"/>" + pageindex);
                      }
                      else
                      {
                          parame = "SelectResult.aspx?t=" + GetTypaNameByNum(ttype) + "&p=" + (i).ToString() + "&s=" + Server.HtmlEncode(searchStr);
                          sb.Append("<img border=\"0\"  src=\"img/blank001.jpg\" width=\"3px\"  style=\"FILTER: alpha(opacity=0);opacity:0;\"/><a href=\"" + parame + "\"><font color=\"blue\">[" + (i).ToString() + "]</font></a>");
                      }
                  }
                  if (pageindex < totalpage)
                  {
                      parame = "SelectResult.aspx?t=" + GetTypaNameByNum(ttype) + "&p=" + (pageindex + 1).ToString() + "&s=" + Server.HtmlEncode(searchStr);
                      sb.Append("<img border=\"0\"  src=\"img/blank001.jpg\" width=\"8px\"   style=\"FILTER: alpha(opacity=0);opacity:0;\"/><a   href=\"" + parame + "\"><font color=\"blue\">下一页</font></a>");
                  }
                  //&nbsp;&nbsp;<font size=2 color=#666699>共" + totalpage .ToString()+ "页</font>
                  sb.Append("</td>");
                  sb.Append("</tr>");
                  sb.Append("</table>");
              }
              returnString = sb.ToString();
          }
          else
          {
              returnString = "<br>抱歉,没有找到该类型“" + searchStr + "”相关的内容。<a href='GoogleResult.aspx?searchword=" + searchStr + "'>可去此处查询</a><br><br><b>建议您:</b> <br>1、看看输入的文字是否有误<br>2、去掉可能不必要的字词,如“的”、“什么”等<br>3、<a href='GoogleResult.aspx?searchword=" + searchStr + "'>去此处查询</a><br><br><br>";
              DivTheSameResults.Attributes.Add("style","display:none");
              divinterfaceAD.Attributes.Add("style", "display:none");
          }
      }
      catch(Exception ex)
      {
          totalcount = 0;
          totalpage = 0;
          returnString = "<br>抱歉,查询错误:"+ex.Message+"。<a href='GoogleResult.aspx?searchword=" + searchStr + "'>可去此处查询</a><br><br><b>建议您:</b> <br>1、看看输入的文字是否有误<br>2、去掉可能不必要的字词,如“的”、“什么”等<br>3、<a href='GoogleResult.aspx?searchword=" + searchStr + "'>去此处查询</a><br><br><br>";
          DivTheSameResults.Attributes.Add("style", "display:none");
          divinterfaceAD.Attributes.Add("style", "display:none");
      }
     return returnString;
 }