public static string parseAntaraKMP(string url) { WebClient W = new WebClient(); string page = W.DownloadString(url); int idx = KMP.kmpMatch(page, "content_news") + 20; if (idx < 0) { Console.WriteLine("isi berita tidak ditemukan"); } else { page = page.Substring(idx); } idx = KMP.kmpMatch(page, "mt10") - 10; if (idx < 0) { Console.WriteLine("isi berita tidak ditemukan"); } else { page = page.Substring(0, idx); } idx = KMP.kmpMatch(page, "<br>"); while (idx != -1) { string front = page.Substring(0, idx); string end = page.Substring(idx + 4); page = front + end; idx = KMP.kmpMatch(page, "<br>"); } return(page); }
public static string parseHTML(string url, int method) { switch (method) { case 0: if (KMP.kmpMatch(url, "detik.com") != -1) { return(parseDetikKMP(url)); } else if (KMP.kmpMatch(url, "tempo.co") != -1) { return(parseTempoKMP(url)); } else if (KMP.kmpMatch(url, "viva") != -1) { return(parseVivaKMP(url)); } else if (KMP.kmpMatch(url, "antara") != -1) { return(parseAntaraKMP(url)); } break; case 1: if (BM.bmMatch(url, "detik.com") != -1) { return(parseDetikBM(url)); } else if (BM.bmMatch(url, "tempo.co") != -1) { return(parseTempoBM(url)); } else if (BM.bmMatch(url, "viva") != -1) { return(parseVivaBM(url)); } else if (BM.bmMatch(url, "antara") != -1) { return(parseAntaraBM(url)); } break; case 2: if (RegexC.regexMatch(url, "detik.com") != -1) { return(parseDetikRegex(url)); } else if (RegexC.regexMatch(url, "tempo.co") != -1) { return(parseTempoRegex(url)); } else if (RegexC.regexMatch(url, "viva") != -1) { return(parseVivaRegex(url)); } else if (RegexC.regexMatch(url, "antara") != -1) { return(parseAntaraRegex(url)); } break; } return("Salah URL"); }
public static string parseVivaKMP(string url) { WebClient W = new WebClient(); string page = W.DownloadString(url); int idx = KMP.kmpMatch(page, "article-content"); if (idx < 0) { Console.WriteLine("isi berita tidak ditemukan"); } else { page = page.Substring(idx); } idx = KMP.kmpMatch(page, "description"); if (idx < 0) { Console.WriteLine("isi berita tidak ditemukan"); } else { page = page.Substring(idx); } idx = KMP.kmpMatch(page, "<p>") + 3; if (idx < 0) { Console.WriteLine("isi berita tidak ditemukan"); } else { page = page.Substring(idx); } idx = KMP.kmpMatch(page, "</span>"); if (idx < 0) { Console.WriteLine("isi berita tidak ditemukan"); } else { page = page.Substring(0, idx); } idx = KMP.kmpMatch(page, "<p>"); while (idx != -1) { string front = page.Substring(0, idx); string end = page.Substring(idx + 3); page = front + end; idx = KMP.kmpMatch(page, "<p>"); } idx = KMP.kmpMatch(page, "</p>"); while (idx != -1) { string front = page.Substring(0, idx); string end = page.Substring(idx + 4); page = front + end; idx = KMP.kmpMatch(page, "</p>"); } idx = KMP.kmpMatch(page, "<em>"); while (idx != -1) { string front = page.Substring(0, idx); string end = page.Substring(idx + 4); page = front + end; idx = KMP.kmpMatch(page, "<em>"); } idx = KMP.kmpMatch(page, "</em>"); while (idx != -1) { string front = page.Substring(0, idx); string end = page.Substring(idx + 5); page = front + end; idx = KMP.kmpMatch(page, "</em>"); } return(page); }
public static String parseDetikKMP(string url) { WebClient W = new WebClient(); string page = W.DownloadString(url); int idx = KMP.kmpMatch(page, "detikdetailtext"); if (idx < 0) { idx = KMP.kmpMatch(page, "p-artikel"); if (idx < 0) { Console.WriteLine("isi berita tidak ditemukan1"); } else { page = page.Substring(idx); } } else { page = page.Substring(idx); } idx = KMP.kmpMatch(page, "<!-- POLONG"); if (idx < 0) { Console.WriteLine("isi berita tidak ditemukan2"); } else { page = page.Substring(0, idx); } idx = KMP.kmpMatch(page, "</p>") + 4; if (idx < 0) { Console.WriteLine("isi berita tidak ditemukan3"); } else { page = page.Substring(idx); } idx = KMP.kmpMatch(page, "<br />"); while (idx != -1) { string front, end; front = page.Substring(0, idx); end = page.Substring(idx + 6); page = front + end; idx = KMP.kmpMatch(page, "<br />"); } idx = KMP.kmpMatch(page, "<br/>"); if (idx < 0) { Console.WriteLine("isi berita tidak ditemukan4"); } else { page = page.Substring(0, idx); } //isx = KMP.kmpMatch(page, ) return(page); }
public static String parseTempoKMP(string url) { WebClient W = new WebClient(); string page = W.DownloadString(url); int idx = KMP.kmpMatch(page, "666666") + 6; if (idx < 6) { idx = KMP.kmpMatch(page, "p-artikel"); if (idx >= 0) { page = page.Substring(idx); } else { Console.WriteLine("isi berita tidak ditemukan1"); } } else { page = page.Substring(idx); idx = KMP.kmpMatch(page, "666666") + 6; if (idx < 6) { Console.WriteLine("isi berita tidak ditemukan2"); } else { page = page.Substring(idx); } } idx = KMP.kmpMatch(page, "</span>") + 10; if (idx < 0) { Console.WriteLine("isi berita tidak ditemukan3"); } else { page = page.Substring(0, idx); } idx = KMP.kmpMatch(page, "<!-- end"); if (idx < 0) { Console.WriteLine("isi berita tidak ditemukan4"); } else { page = page.Substring(0, idx); } idx = KMP.kmpMatch(page, "<br />"); while (idx != -1) { string front = page.Substring(0, idx); string end = page.Substring(idx + 6); page = front + end; idx = KMP.kmpMatch(page, "<br />"); } idx = KMP.kmpMatch(page, "<em>"); while (idx != -1) { string front = page.Substring(0, idx); string end = page.Substring(idx + 4); page = front + end; idx = KMP.kmpMatch(page, "<em>"); } idx = KMP.kmpMatch(page, "</em>"); while (idx != -1) { string front = page.Substring(0, idx); string end = page.Substring(idx + 5); page = front + end; idx = KMP.kmpMatch(page, "</em>"); } idx = KMP.kmpMatch(page, "</a>"); while (idx != -1) { string front = page.Substring(0, idx); string end = page.Substring(idx + 4); page = front + end; idx = KMP.kmpMatch(page, "</a>"); } idx = KMP.kmpMatch(page, "</p>"); while (idx != -1) { string front = page.Substring(0, idx); string end = page.Substring(idx + 4); page = front + end; idx = KMP.kmpMatch(page, "</p>"); } return(page); }