Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using HtmlAgilityPack;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Threading;
- namespace bot_benchmark
- {
- class Program
- {
- public static List<string> UrlList = new List<string>();
- static void Main(string[] args)
- {
- Console.WriteLine("Aşağıdakilerden biri Seç");
- Console.WriteLine(" htmlagilitypack \n regex ");
- string selectedmethod = Console.ReadLine();
- Console.WriteLine("url giriniz");
- string url = Console.ReadLine();
- if (selectedmethod == "htmlagilitypack")
- {
- DateTime startdate = DateTime.Now;
- Console.WriteLine(startdate.ToString("h:mm:ss"));
- HtmlAgilityPackMethod(url);
- DateTime enddate = DateTime.Now;
- Console.WriteLine(enddate.ToString("h:mm:ss"));
- Console.WriteLine(enddate-startdate);
- Console.WriteLine(UrlList.Count.ToString());
- }
- else if (selectedmethod == "regex")
- {
- DateTime startdate = DateTime.Now;
- Console.WriteLine(startdate.ToString("h:mm:ss"));
- RegexMethod(url);
- DateTime enddate = DateTime.Now;
- Console.WriteLine(enddate.ToString("h:mm:ss"));
- Console.WriteLine(enddate-startdate);
- Console.WriteLine(UrlList.Count.ToString());
- }
- else
- {
- //Todo:
- }
- Console.ReadLine();
- }
- static void HtmlAgilityPackMethod(string url)
- {
- HtmlDocument dokuman = new HtmlDocument();
- dokuman.LoadHtml(GetDownloadString(url));
- HtmlNodeCollection basliklar = dokuman.DocumentNode.SelectNodes("//a[@href]");
- foreach (var baslik in basliklar)
- {
- string hrefValue = baslik.GetAttributeValue("href", string.Empty);
- UrlList.Add(hrefValue);
- }
- }
- static void RegexMethod(string url)
- {
- Regex r = new Regex(@"<(a).*?href=(""|')(.+?)(""|').*?>");
- MatchCollection matchlist = r.Matches(GetDownloadString(url));
- foreach (Match match in matchlist)
- {
- UrlList.Add(match.Value);
- }
- }
- private static string GetDownloadString(string link)
- {
- WebClient client = new WebClient();
- Uri url = new Uri(link);
- client.Encoding = Encoding.UTF8;
- client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
- string html = client.DownloadString(url);
- return html;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement