public static int UpdateCnInterfaceVideo(CnDataAcess.Entity.CnInterfaceVideoXpath cnXpath) { return ObjectCreate.CreateInterfaceVideoXpath().UpdateCnInterfaceVideo(cnXpath); }
public int UpdateCnInterfaceVideo(CnDataAcess.Entity.CnInterfaceVideoXpath cnxpath) { int resultcount = 0; string sql = @"IF NOT EXISTS(SELECT 1 FROM [Cn_InterfaceVideoXpath] WHERE [CnWebName] = @CnWebName) BEGIN INSERT INTO [Cn_InterfaceVideoXpath] ([CnWebName] ,[CnWebUrl] ,[CnWebEncode] ,[CnVideoTitle001] ,[CnVideoHref001] ,[CnVideoSrc001] ,[CnVideoTitle002] ,[CnVideoHref002] ,[CnVideoSrc002] ,[CnVideoTitle003] ,[CnVideoHref003] ,[CnVideoSrc003] ,[CnVideoTitle004] ,[CnVideoHref004] ,[CnVideoSrc004] ,[CnVideoTitle005] ,[CnVideoHref005] ,[CnVideoSrc005] ,[CnVideoTitle006] ,[CnVideoHref006] ,[CnVideoSrc006]) VALUES (@CnWebName ,@CnWebUrl ,@CnWebEncode ,@CnVideoTitle001 ,@CnVideoHref001 ,@CnVideoSrc001 ,@CnVideoTitle002 ,@CnVideoHref002 ,@CnVideoSrc002 ,@CnVideoTitle003 ,@CnVideoHref003 ,@CnVideoSrc003 ,@CnVideoTitle004 ,@CnVideoHref004 ,@CnVideoSrc004 ,@CnVideoTitle005 ,@CnVideoHref005 ,@CnVideoSrc005 ,@CnVideoTitle006 ,@CnVideoHref006 ,@CnVideoSrc006) END ELSE BEGIN UPDATE [Cn_InterfaceVideoXpath] SET [CnWebName] = @CnWebName ,[CnWebUrl] = @CnWebUrl ,[CnWebEncode]=@CnWebEncode ,[CnVideoTitle001] = @CnVideoTitle001 ,[CnVideoHref001] = @CnVideoHref001 ,[CnVideoSrc001] = @CnVideoSrc001 ,[CnVideoTitle002] = @CnVideoTitle002 ,[CnVideoHref002] = @CnVideoHref002 ,[CnVideoSrc002] = @CnVideoSrc002 ,[CnVideoTitle003] = @CnVideoTitle003 ,[CnVideoHref003] = @CnVideoHref003 ,[CnVideoSrc003] = @CnVideoSrc003 ,[CnVideoTitle004] = @CnVideoTitle004 ,[CnVideoHref004] = @CnVideoHref004 ,[CnVideoSrc004] = @CnVideoSrc004 ,[CnVideoTitle005] = @CnVideoTitle005 ,[CnVideoHref005] = @CnVideoHref005 ,[CnVideoSrc005] = @CnVideoSrc005 ,[CnVideoTitle006] = @CnVideoTitle006 ,[CnVideoHref006] = @CnVideoHref006 ,[CnVideoSrc006] = @CnVideoSrc006 ,[CnUpdateTime] = getdate() WHERE [CnWebName]=@CnWebName END"; string conStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionStr"].ToString(); using (SqlConnection conn = new SqlConnection(conStr)) { conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = sql; cmd.Parameters.AddWithValue("@CnWebName", cnxpath.CnWebName); cmd.Parameters.AddWithValue("@CnWebUrl", cnxpath.CnWebUrl); cmd.Parameters.AddWithValue("@CnWebEncode", cnxpath.CnWebEncode); cmd.Parameters.AddWithValue("@CnVideoTitle001", cnxpath.CnVideoTitle001); cmd.Parameters.AddWithValue("@CnVideoHref001", cnxpath.CnVideoHref001); cmd.Parameters.AddWithValue("@CnVideoSrc001", cnxpath.CnVideoSrc001); cmd.Parameters.AddWithValue("@CnVideoTitle002", cnxpath.CnVideoTitle002); cmd.Parameters.AddWithValue("@CnVideoHref002", cnxpath.CnVideoHref002); cmd.Parameters.AddWithValue("@CnVideoSrc002", cnxpath.CnVideoSrc002); cmd.Parameters.AddWithValue("@CnVideoTitle003", cnxpath.CnVideoTitle003); cmd.Parameters.AddWithValue("@CnVideoHref003", cnxpath.CnVideoHref003); cmd.Parameters.AddWithValue("@CnVideoSrc003", cnxpath.CnVideoSrc003); cmd.Parameters.AddWithValue("@CnVideoTitle004", cnxpath.CnVideoTitle004); cmd.Parameters.AddWithValue("@CnVideoHref004", cnxpath.CnVideoHref004); cmd.Parameters.AddWithValue("@CnVideoSrc004", cnxpath.CnVideoSrc004); cmd.Parameters.AddWithValue("@CnVideoTitle005", cnxpath.CnVideoTitle005); cmd.Parameters.AddWithValue("@CnVideoHref005", cnxpath.CnVideoHref005); cmd.Parameters.AddWithValue("@CnVideoSrc005", cnxpath.CnVideoSrc005); cmd.Parameters.AddWithValue("@CnVideoTitle006", cnxpath.CnVideoTitle006); cmd.Parameters.AddWithValue("@CnVideoHref006", cnxpath.CnVideoHref006); cmd.Parameters.AddWithValue("@CnVideoSrc006", cnxpath.CnVideoSrc006); resultcount = cmd.ExecuteNonQuery(); } return resultcount; }
public void GetWebVideoHtml(CnDataAcess.Entity.CnInterfaceVideoXpath cnXpath,string title,string alt,string src,string hrefpath,string srcpath,string htmlname) { WebClient wc = new WebClient { Encoding = Encoding.GetEncoding(cnXpath.CnWebEncode) }; string html = wc.DownloadString(cnXpath.CnWebUrl); //string html = ""; //System.IO.StreamReader sr = new System.IO.StreamReader("D:\\CnInterface\\CnWeb\\html\\buildhtml.txt", Encoding.GetEncoding("gb2312")); //lock (sr) //{ // html = sr.ReadToEnd(); // sr.Close(); //} HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); string title001 = ""; string title002 = ""; string title003 = ""; string title004 = ""; string title005 = ""; string title006 = ""; if (!title.Equals("") && alt.Equals("")) { title001 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle001).Attributes["title"].Value; title002 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle002).Attributes["title"].Value; title003 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle003).Attributes["title"].Value; title004 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle004).Attributes["title"].Value; title005 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle005).Attributes["title"].Value; title006 = cnXpath.CnVideoTitle006.Equals("") ? cnXpath.CnVideoTitle006 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle006).Attributes["title"].Value; } else if (title.Equals("") && !alt.Equals("")) { title001 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle001).Attributes["alt"].Value; title002 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle002).Attributes["alt"].Value; title003 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle003).Attributes["alt"].Value; title004 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle004).Attributes["alt"].Value; title005 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle005).Attributes["alt"].Value; title006 =cnXpath.CnVideoTitle006.Equals("")?cnXpath.CnVideoTitle006:doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle006).Attributes["alt"].Value; } else { title001 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle001).InnerText; title002 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle002).InnerText; title003 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle003).InnerText; title004 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle004).InnerText; title005 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle005).InnerText; title006 = cnXpath.CnVideoTitle006.Equals("") ? cnXpath.CnVideoTitle006 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle006).InnerText; } StringBuilder sb = new StringBuilder(); sb.Append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>www.CnInterface.com接口天下</title><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" /> <meta name=\"keywords\" content=\"接口,接口天下,价值接口,程序接口,网络接口,webservice接口,http接口,ActiveX dll接口,普通dll接口,数据库接口,短信,短信发送,短信在线发送,手机短信,手机短信发送,手机短信在线发送\" /><style type=\"text/css\">a:link {text-decoration:none;color:#666699;}a:visited {text-decoration:none;color:#666699}a:hover {text-decoration:underline; color:#666699; cursor:hand;}a:active {text-decoration:none;color:#666699}</style><link href=\"../css/base.css\" type=\"text/css\" rel=\"Stylesheet\" /></head>"); sb.Append("<body>"); sb.Append("<table border=\"0\" cellpadding =\"2\" cellspacing =\"0\" width=\"100%\" >"); sb.Append("<tr>"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref001.Equals("") ? cnXpath.CnVideoHref001 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref001).Attributes["href"].Value) + "\" target=\"_blank\"><img border=\"0\" src=\"" + srcpath + (cnXpath.CnVideoSrc001.Equals("")?cnXpath.CnVideoSrc001:doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoSrc001).Attributes[src].Value) + "\" width=\"130px\" height=\"88px\" alt=\"" + title001 + "\"/></a></td>"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref002.Equals("") ? cnXpath.CnVideoHref002 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref002).Attributes["href"].Value) + "\" target=\"_blank\"><img border=\"0\" src=\"" + srcpath + (cnXpath.CnVideoSrc002.Equals("") ? cnXpath.CnVideoSrc002 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoSrc002).Attributes[src].Value) + "\" width=\"130px\" height=\"88px\" alt=\"" + title002 + "\"/></a></td>"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref003.Equals("") ? cnXpath.CnVideoHref003 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref003).Attributes["href"].Value) + "\" target=\"_blank\"><img border=\"0\" src=\"" + srcpath + (cnXpath.CnVideoSrc003.Equals("") ? cnXpath.CnVideoSrc003 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoSrc003).Attributes[src].Value) + "\" width=\"130px\" height=\"88px\" alt=\"" + title003 + "\"/></a></td>"); sb.Append("</tr>"); sb.Append("<tr>"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref001.Equals("") ? cnXpath.CnVideoHref001 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref001).Attributes["href"].Value) + "\" target=\"_blank\"><font size='2' color='#003399'>" + title001 + "</font></a></td>"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref002.Equals("") ? cnXpath.CnVideoHref002 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref002).Attributes["href"].Value) + "\" target=\"_blank\"><font size='2' color='#003399'>" + title002 + "</font></a></td>"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref003.Equals("") ? cnXpath.CnVideoHref003 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref003).Attributes["href"].Value) + "\" target=\"_blank\"><font size='2' color='#003399'>" + title003 + "</font></a></td>"); sb.Append("</tr>"); sb.Append("<tr>"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref004.Equals("") ? cnXpath.CnVideoHref004 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref004).Attributes["href"].Value) + "\" target=\"_blank\"><img border=\"0\" src=\"" + srcpath + (cnXpath.CnVideoSrc004.Equals("") ? cnXpath.CnVideoSrc004 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoSrc004).Attributes[src].Value) + "\" width=\"130px\" height=\"88px\" alt=\"" + title004 + "\"/></a></td>"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref005.Equals("") ? cnXpath.CnVideoHref005 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref005).Attributes["href"].Value) + "\" target=\"_blank\"><img border=\"0\" src=\"" + srcpath + (cnXpath.CnVideoSrc005.Equals("") ? cnXpath.CnVideoSrc005 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoSrc005).Attributes[src].Value) + "\" width=\"130px\" height=\"88px\" alt=\"" + title005 + "\"/></a></td>"); if (cnXpath.CnVideoHref006.Equals("")) { sb.Append("<td> </td>"); } else { sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref006.Equals("") ? cnXpath.CnVideoHref006 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref006).Attributes["href"].Value) + "\" target=\"_blank\"><img border=\"0\" src=\"" + srcpath + (cnXpath.CnVideoSrc006.Equals("") ? cnXpath.CnVideoSrc006 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoSrc006).Attributes[src].Value) + "\" width=\"130px\" height=\"88px\" alt=\"" + title006 + "\"/></a></td>"); } sb.Append("</tr>"); sb.Append("<tr>"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref004.Equals("") ? cnXpath.CnVideoHref004 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref004).Attributes["href"].Value) + "\" target=\"_blank\"><font size='2' color='#003399'>" + title004 + "</font></a></td>"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref005.Equals("") ? cnXpath.CnVideoHref005 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref005).Attributes["href"].Value) + "\" target=\"_blank\"><font size='2' color='#003399'>" + title005 + "</font></a></td>"); if (cnXpath.CnVideoHref006.Equals("")) { sb.Append("<td> </td>"); } else { sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref006.Equals("") ? cnXpath.CnVideoHref006 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref006).Attributes["href"].Value) + "\" target=\"_blank\"><font size='2' color='#003399'>" + title006 + "</font></a></td>"); } sb.Append("</tr>"); sb.Append("</table>"); sb.Append("</body></html>"); if (!System.IO.File.Exists(System.Configuration.ConfigurationSettings.AppSettings["CreateHtmlPath"].ToString() + htmlname + ".html")) { System.IO.File.Create(System.Configuration.ConfigurationSettings.AppSettings["CreateHtmlPath"].ToString() + htmlname + ".html"); } StreamWriter sw = new StreamWriter(System.Configuration.ConfigurationSettings.AppSettings["CreateHtmlPath"].ToString() + htmlname + ".html"); sw.Write(sb.ToString()); sw.Close(); System.Threading.Thread.Sleep(1000); }
public string GetWebImagesXml(CnDataAcess.Entity.CnInterfaceVideoXpath cnXpath, string title, string alt, string src, string hrefpath, string srcpath, string htmlname,int bid,out int id) { WebClient wc = new WebClient { Encoding = Encoding.GetEncoding(cnXpath.CnWebEncode) }; string html = wc.DownloadString(cnXpath.CnWebUrl); //string html = ""; //System.IO.StreamReader sr = new System.IO.StreamReader("D:\\CnInterface\\CnWeb\\html\\buildhtml.txt", Encoding.GetEncoding("gb2312")); //lock (sr) //{ // html = sr.ReadToEnd(); // sr.Close(); //} HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); string title001 = ""; string title002 = ""; string title003 = ""; string title004 = ""; string title005 = ""; string title006 = ""; if (!title.Equals("") && alt.Equals("")) { title001 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle001).Attributes["title"].Value; title002 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle002).Attributes["title"].Value; title003 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle003).Attributes["title"].Value; title004 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle004).Attributes["title"].Value; title005 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle005).Attributes["title"].Value; title006 = cnXpath.CnVideoTitle006.Equals("") ? cnXpath.CnVideoTitle006 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle006).Attributes["title"].Value; } else if (title.Equals("") && !alt.Equals("")) { title001 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle001).Attributes["alt"].Value; title002 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle002).Attributes["alt"].Value; title003 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle003).Attributes["alt"].Value; title004 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle004).Attributes["alt"].Value; title005 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle005).Attributes["alt"].Value; title006 = cnXpath.CnVideoTitle006.Equals("") ? cnXpath.CnVideoTitle006 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle006).Attributes["alt"].Value; } else { title001 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle001).InnerText; title002 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle002).InnerText; title003 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle003).InnerText; title004 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle004).InnerText; title005 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle005).InnerText; title006 = cnXpath.CnVideoTitle006.Equals("") ? cnXpath.CnVideoTitle006 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle006).InnerText; } HtmlToText ht = new HtmlToText(); title001 = ht.ConvertHtml(title001).Trim(); title002 = ht.ConvertHtml(title002).Trim(); title003 = ht.ConvertHtml(title003).Trim(); title004 = ht.ConvertHtml(title004).Trim(); title005 = ht.ConvertHtml(title005).Trim(); title006 = ht.ConvertHtml(title006).Trim(); string code = htmlname.Replace("Videos", ""); htmlname = GetWebInfoByCode(code, 0); string weburl = GetWebInfoByCode(code, 1); StringBuilder sb = new StringBuilder(); // int id = 0; //第一条 bid++; sb.Append("<img id=\"" + bid + "\">"); sb.Append("<web>" + htmlname + "</web>"); sb.Append("<title>" + title001 + "</title>"); sb.Append("<url>" + hrefpath + (cnXpath.CnVideoHref001.Equals("") ? cnXpath.CnVideoHref001 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref001).Attributes["href"].Value).Replace("&", "$") + "</url>"); sb.Append("<src>" + srcpath + (cnXpath.CnVideoSrc001.Equals("") ? cnXpath.CnVideoSrc001 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoSrc001).Attributes[src].Value).Replace("&", "$") + "</src>"); sb.Append("<weburl>" + weburl + "</weburl>"); sb.Append("</img>"); //第二条 bid++; sb.Append("<img id=\"" + bid + "\">"); sb.Append("<web>" + htmlname + "</web>"); sb.Append("<title>" + title002 + "</title>"); sb.Append("<url>" + hrefpath + (cnXpath.CnVideoHref002.Equals("") ? cnXpath.CnVideoHref002 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref002).Attributes["href"].Value).Replace("&", "$") + "</url>"); sb.Append("<src>" + srcpath + (cnXpath.CnVideoSrc002.Equals("") ? cnXpath.CnVideoSrc002 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoSrc002).Attributes[src].Value).Replace("&", "$") + "</src>"); sb.Append("<weburl>" + weburl + "</weburl>"); sb.Append("</img>"); //第三条 bid++; sb.Append("<img id=\"" + bid + "\">"); sb.Append("<web>" + htmlname + "</web>"); sb.Append("<title>" + title003 + "</title>"); sb.Append("<url>" + hrefpath + (cnXpath.CnVideoHref003.Equals("") ? cnXpath.CnVideoHref003 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref003).Attributes["href"].Value).Replace("&", "$") + "</url>"); sb.Append("<src>" + srcpath + (cnXpath.CnVideoSrc003.Equals("") ? cnXpath.CnVideoSrc003 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoSrc003).Attributes[src].Value).Replace("&", "$") + "</src>"); sb.Append("<weburl>" + weburl + "</weburl>"); sb.Append("</img>"); //第四条 bid++; sb.Append("<img id=\"" + bid + "\">"); sb.Append("<web>" + htmlname + "</web>"); sb.Append("<title>" + title004 + "</title>"); sb.Append("<url>" + hrefpath + (cnXpath.CnVideoHref004.Equals("") ? cnXpath.CnVideoHref004 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref004).Attributes["href"].Value).Replace("&", "$") + "</url>"); sb.Append("<src>" + srcpath + (cnXpath.CnVideoSrc004.Equals("") ? cnXpath.CnVideoSrc004 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoSrc004).Attributes[src].Value).Replace("&", "$") + "</src>"); sb.Append("<weburl>" + weburl + "</weburl>"); sb.Append("</img>"); //第五条 bid++; sb.Append("<img id=\"" + bid + "\">"); sb.Append("<web>" + htmlname + "</web>"); sb.Append("<title>" + title005 + "</title>"); sb.Append("<url>" + hrefpath + (cnXpath.CnVideoHref005.Equals("") ? cnXpath.CnVideoHref005 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref005).Attributes["href"].Value).Replace("&", "$") + "</url>"); sb.Append("<src>" + srcpath + (cnXpath.CnVideoSrc005.Equals("") ? cnXpath.CnVideoSrc005 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoSrc005).Attributes[src].Value).Replace("&", "$") + "</src>"); sb.Append("<weburl>" + weburl + "</weburl>"); sb.Append("</img>"); //第六条 if (!cnXpath.CnVideoHref006.Equals("")) { bid++; sb.Append("<img id=\"" + bid + "\">"); sb.Append("<web>" + htmlname + "</web>"); sb.Append("<title>" + title006 + "</title>"); sb.Append("<url>" + hrefpath + (cnXpath.CnVideoHref006.Equals("") ? cnXpath.CnVideoHref006 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref006).Attributes["href"].Value).Replace("&", "$") + "</url>"); sb.Append("<src>" + srcpath + (cnXpath.CnVideoSrc006.Equals("") ? cnXpath.CnVideoSrc006 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoSrc006).Attributes[src].Value).Replace("&", "$") + "</src>"); sb.Append("<weburl>" + weburl + "</weburl>"); sb.Append("</img>"); } id = bid; return sb.ToString(); }
public string GetWebVideoHtml(CnDataAcess.Entity.CnInterfaceVideoXpath cnXpath, string title, string alt, string src, string hrefpath, string srcpath) { WebClient wc = new WebClient { Encoding = Encoding.GetEncoding(cnXpath.CnWebEncode) }; string html = wc.DownloadString(cnXpath.CnWebUrl); //string html = ""; //System.IO.StreamReader sr = new System.IO.StreamReader(System.Configuration.ConfigurationSettings.AppSettings["CreateHtmlPath"].ToString()+ "buildhtml.txt", Encoding.GetEncoding("gb2312")); //lock (sr) //{ // html = sr.ReadToEnd(); // sr.Close(); //} HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); string title001 = ""; string title002 = ""; string title003 = ""; string title004 = ""; string title005 = ""; string title006 = ""; if (!title.Equals("") && alt.Equals("")) { title001 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle001).Attributes["title"].Value; title002 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle002).Attributes["title"].Value; title003 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle003).Attributes["title"].Value; title004 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle004).Attributes["title"].Value; title005 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle005).Attributes["title"].Value; title006 = cnXpath.CnVideoTitle006.Equals("") ? cnXpath.CnVideoTitle006 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle006).Attributes["title"].Value; } else if (title.Equals("") && !alt.Equals("")) { title001 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle001).Attributes["alt"].Value; title002 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle002).Attributes["alt"].Value; title003 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle003).Attributes["alt"].Value; title004 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle004).Attributes["alt"].Value; title005 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle005).Attributes["alt"].Value; title006 = cnXpath.CnVideoTitle006.Equals("") ? cnXpath.CnVideoTitle006 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle006).Attributes["alt"].Value; } else { title001 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle001).InnerText; title002 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle002).InnerText; title003 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle003).InnerText; title004 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle004).InnerText; title005 = doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle005).InnerText; title006 = cnXpath.CnVideoTitle006.Equals("") ? cnXpath.CnVideoTitle006 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoTitle006).InnerText; } StringBuilder sb = new StringBuilder(); sb.Append("<table border=\"0\" cellpadding =\"2\" cellspacing =\"4\" width=\"100%\" >"); sb.Append("<tr align=\"center\">"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref001.Equals("") ? cnXpath.CnVideoHref001 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref001).Attributes["href"].Value) + "\" target=\"_blank\"><img border=\"0\" src=\"" + srcpath + (cnXpath.CnVideoSrc001.Equals("") ? cnXpath.CnVideoSrc001 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoSrc001).Attributes[src].Value) + "\" width=\"130px\" height=\"88px\" alt=\"" + title001 + "\"/></a></td>"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref002.Equals("") ? cnXpath.CnVideoHref002 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref002).Attributes["href"].Value) + "\" target=\"_blank\"><img border=\"0\" src=\"" + srcpath + (cnXpath.CnVideoSrc002.Equals("") ? cnXpath.CnVideoSrc002 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoSrc002).Attributes[src].Value) + "\" width=\"130px\" height=\"88px\" alt=\"" + title002 + "\"/></a></td>"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref003.Equals("") ? cnXpath.CnVideoHref003 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref003).Attributes["href"].Value) + "\" target=\"_blank\"><img border=\"0\" src=\"" + srcpath + (cnXpath.CnVideoSrc003.Equals("") ? cnXpath.CnVideoSrc003 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoSrc003).Attributes[src].Value) + "\" width=\"130px\" height=\"88px\" alt=\"" + title003 + "\"/></a></td>"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref004.Equals("") ? cnXpath.CnVideoHref004 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref004).Attributes["href"].Value) + "\" target=\"_blank\"><img border=\"0\" src=\"" + srcpath + (cnXpath.CnVideoSrc004.Equals("") ? cnXpath.CnVideoSrc004 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoSrc004).Attributes[src].Value) + "\" width=\"130px\" height=\"88px\" alt=\"" + title004 + "\"/></a></td>"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref005.Equals("") ? cnXpath.CnVideoHref005 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref005).Attributes["href"].Value) + "\" target=\"_blank\"><img border=\"0\" src=\"" + srcpath + (cnXpath.CnVideoSrc005.Equals("") ? cnXpath.CnVideoSrc005 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoSrc005).Attributes[src].Value) + "\" width=\"130px\" height=\"88px\" alt=\"" + title005 + "\"/></a></td>"); if (cnXpath.CnVideoHref006.Equals("")) { sb.Append("<td> </td>"); } else { sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref006.Equals("") ? cnXpath.CnVideoHref006 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref006).Attributes["href"].Value) + "\" target=\"_blank\"><img border=\"0\" src=\"" + srcpath + (cnXpath.CnVideoSrc006.Equals("") ? cnXpath.CnVideoSrc006 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoSrc006).Attributes[src].Value) + "\" width=\"130px\" height=\"88px\" alt=\"" + title006 + "\"/></a></td>"); } sb.Append("</tr>"); sb.Append("<tr>"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref001.Equals("") ? cnXpath.CnVideoHref001 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref001).Attributes["href"].Value) + "\" target=\"_blank\" title=\""+title001+"\"><font size='2' color='#003399'>" + getStr(title001,20) + "</font></a></td>"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref002.Equals("") ? cnXpath.CnVideoHref002 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref002).Attributes["href"].Value) + "\" target=\"_blank\" title=\"" + title002 + "\"><font size='2' color='#003399'>" + getStr(title002,20) + "</font></a></td>"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref003.Equals("") ? cnXpath.CnVideoHref003 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref003).Attributes["href"].Value) + "\" target=\"_blank\" title=\"" + title003 + "\"><font size='2' color='#003399'>" + getStr(title003, 20) + "</font></a></td>"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref004.Equals("") ? cnXpath.CnVideoHref004 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref004).Attributes["href"].Value) + "\" target=\"_blank\" title=\"" + title004 + "\"><font size='2' color='#003399'>" + getStr(title004, 20) + "</font></a></td>"); sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref005.Equals("") ? cnXpath.CnVideoHref005 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref005).Attributes["href"].Value) + "\" target=\"_blank\" title=\"" + title005 + "\"><font size='2' color='#003399'>" + getStr(title005, 20) + "</font></a></td>"); if (cnXpath.CnVideoHref006.Equals("")) { sb.Append("<td> </td>"); } else { sb.Append(" <td><a href=\"" + hrefpath + (cnXpath.CnVideoHref006.Equals("") ? cnXpath.CnVideoHref006 : doc.DocumentNode.SelectSingleNode(cnXpath.CnVideoHref006).Attributes["href"].Value) + "\" target=\"_blank\" title=\"" + title006 + "\"><font size='2' color='#003399'>" + getStr(title006, 20) + "</font></a></td>"); } sb.Append("</tr>"); sb.Append("</table>"); return sb.ToString(); }