public int InsertCollectSongInfo(CollectSongInfo collectSongInfo) { int result = 0; try { SqlParameter[] parms = new SqlParameter[] { new SqlParameter("showCollectId", collectSongInfo.ShowCollectId), new SqlParameter("xm_SongId", collectSongInfo.XM_SongId), new SqlParameter("songName", collectSongInfo.SongName), new SqlParameter("singer", collectSongInfo.Singer) }; result = HelperSQL.ExecNonQuery("usp_XMSpiderCollect_Insert_CollectSongInfo", parms); } catch (Exception ex) { LogBLL.Error("InsertCollectSongInfo", ex); } return(result); }
public void CollectSongAction(LayerCollect layerCollect) { CollectSongInfo collectSongInfo = new CollectSongInfo(); //http://www.xiami.com/song/showcollect/id/2678242?spm=0.0.0.0.zBzAv4 // string fileXmlPath = FolderPath + "TextFile2.txt"; // string html = File.ReadAllText(fileXmlPath, Encoding.UTF8); Thread.Sleep(6000); string html = HttpHelper.Open(string.Format(CollectTemplateXml.CollectSongAttr_url, layerCollect.ShowCollectId), "UTF-8"); //string path = TestFolderPath + "CollectSongPage\\" + layerCollect.ShowCollectId + ".txt"; //bool b = WriteFile(path, html, FileType.CollectSongInfo); //if (!b) //{ // return; //} //这个暂时不用 string palyTimes = CommonHelper.GetMatchRegex(CollectTemplateXml.CollectSong_Play, html); string recommend = CommonHelper.GetMatchRegex(CollectTemplateXml.CollectSong_Recommend, html); string collect = CommonHelper.GetMatchRegex(CollectTemplateXml.CollectSong_Collect, html); string tags = CommonHelper.NoHTML(CommonHelper.GetMatchRegex(CollectTemplateXml.CollectSong_Tags, html)); layerCollect.PalyTimes = int.Parse(palyTimes); layerCollect.RecommendTimes = int.Parse(recommend); layerCollect.CollectTimes = int.Parse(collect); layerCollect.Tags = tags; collctService.InsertLayerCollect(layerCollect); string main = CommonHelper.GetMatchRegexFull(CollectTemplateXml.SongInfo_Main, html); List <string> ListUnit = CommonHelper.GetMatchRegexList(CollectTemplateXml.SongInfo_Unit, main); foreach (string unit in ListUnit) { try { string songId = CommonHelper.GetMatchRegex(CollectTemplateXml.SongInfo_SongId, unit); string songname = CommonHelper.NoHTML(CommonHelper.GetMatchRegex(CollectTemplateXml.SongInfo_SongName, unit)); string singer = CommonHelper.NoHTML(CommonHelper.GetMatchRegex(CollectTemplateXml.SongInfo_Singer, unit)); if (songId == "") { songId = CommonHelper.GetMatchRegex("id=\"totle_(.+?)\"", unit); singer = CommonHelper.NoHTML(CommonHelper.GetMatchRegex("<a href=\"/artist/\\d+\" title=\"\">(.+?)</a>", unit)); } collectSongInfo.ShowCollectId = layerCollect.ShowCollectId; collectSongInfo.XM_SongId = int.Parse(songId); collectSongInfo.SongName = songname; collectSongInfo.Singer = singer; collctService.InsertCollectSongInfo(collectSongInfo); } catch (Exception ex) { LogNet.LogBLL.Error("CollectSongAction [foreach] 异常", ex); } } }