static void Main(string[] args) { var option = new ChromeOptions(); option.AddArgument("no-sandbox"); option.AddArgument("--start-maximized"); option.AddUserProfilePreference("profile.default_content_setting_values.images", 2); option.AddUserProfilePreference("profile.default_content_setting_values.stylesheet", 2); ChromeDriver driver = new ChromeDriver(option); driver.Navigate().GoToUrl(GlobalLink); for (int i = 0; i < 150; i++) { driver.ExecuteScript("scroll(0, 125000);"); var more = driver.FindElement(By.Id("pagination")); more.Click(); Thread.Sleep(300); } var pageSource = driver.PageSource; var categore = new Categores(); var docStars = new HtmlDocument(); docStars.LoadHtml(pageSource); var userItems = docStars.DocumentNode.SelectNodes(".//div[@class='user-item']"); categore.Profiles = new List <Profile>(); foreach (var userItem in userItems) { try { var client1 = new WebClient(); var profile = new Profile(); var name = userItem.SelectSingleNode(".//h3").InnerText; var folow = userItem.SelectNodes(".//p")[1].InnerText; profile.Abonnés = folow; var href = userItem.SelectSingleNode(".//a[@class='avatar']").GetAttributeValue("href", ""); profile.ProfilePageUrl = href; profile.Nickname = name; var profileContent = client1.DownloadString(href); var doc = new HtmlDocument(); doc.LoadHtml(profileContent); var websiteUrl = doc.DocumentNode.SelectSingleNode(".//div[@class='profile-wrap']") .SelectSingleNode(".//p[@class='profile-blog']").SelectSingleNode(".//a") .GetAttributeValue("href", ""); profile.WebsiteUrl = websiteUrl; GetSocial(websiteUrl, profile); categore.Profiles.Add(profile); Console.WriteLine(categore.Profiles.Count); } catch (Exception) { } } categore.CategoreName = "lifestyle"; var json = JsonConvert.SerializeObject(categore); File.WriteAllText(@"D:\lifestyle.json", json); //NewMethod(); }
private static void NewMethod() { var models = new List <Categores>(); var client = new WebClient(); var downloadString = client.DownloadString(Link); var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(downloadString); var userCategorys = htmlDoc.DocumentNode.SelectNodes(".//div[@class='user-cat']"); foreach (var userCategory in userCategorys) { try { var categore = new Categores(); var cat = userCategory.SelectSingleNode(".//div[@class='user-group-header']").SelectSingleNode(".//a") .InnerText.Split('&').First().Trim(); categore.CategoreName = cat; var catLink = userCategory.SelectSingleNode(".//div[@class='user-group-header']").SelectSingleNode(".//a") .GetAttributeValue("href", ""); var lesStars = client.DownloadString(catLink); var docStars = new HtmlDocument(); docStars.LoadHtml(lesStars); var userItems = docStars.DocumentNode.SelectNodes(".//div[@class='user-item']"); if (userItems is null) { continue; } categore.Profiles = new List <Profile>(); foreach (var userItem in userItems) { try { var client1 = new WebClient(); var profile = new Profile(); var name = userItem.SelectSingleNode(".//h3").InnerText; var folow = userItem.SelectNodes(".//p")[1].InnerText; profile.Abonnés = folow; var href = userItem.SelectSingleNode(".//a[@class='avatar']").GetAttributeValue("href", ""); profile.ProfilePageUrl = href; profile.Nickname = name; var profileContent = client1.DownloadString(href); var doc = new HtmlDocument(); doc.LoadHtml(profileContent); var websiteUrl = doc.DocumentNode.SelectSingleNode(".//div[@class='profile-wrap']") .SelectSingleNode(".//p[@class='profile-blog']").SelectSingleNode(".//a") .GetAttributeValue("href", ""); profile.WebsiteUrl = websiteUrl; GetSocial(websiteUrl, profile); categore.Profiles.Add(profile); } catch (Exception) { } } var client2 = new WebClient(); var linkDeb = docStars.DocumentNode.SelectSingleNode(".//ul[@class='user-group-switch group']") .ChildNodes[3].ChildNodes[1].GetAttributeValue("href", ""); var lesDebutantes = client2.DownloadString(linkDeb); var docDebutantes = new HtmlDocument(); docDebutantes.LoadHtml(lesDebutantes); var userItemsDebutantes = docDebutantes.DocumentNode.SelectNodes(".//div[@class='user-item']"); if (userItemsDebutantes is null) { continue; } foreach (var userItem in userItemsDebutantes) { try { var client1 = new WebClient(); var profile = new Profile(); var name = userItem.SelectSingleNode(".//h3").InnerText; var folow = userItem.SelectNodes(".//p")[1].InnerText; profile.Abonnés = folow; var href = userItem.SelectSingleNode(".//a[@class='avatar']").GetAttributeValue("href", ""); profile.ProfilePageUrl = href; profile.Nickname = name; var profileContent = client1.DownloadString(href); var doc = new HtmlDocument(); doc.LoadHtml(profileContent); var websiteUrl = doc.DocumentNode.SelectSingleNode(".//div[@class='profile-wrap']") .SelectSingleNode(".//p[@class='profile-blog']").SelectSingleNode(".//a") .GetAttributeValue("href", ""); profile.WebsiteUrl = websiteUrl; GetSocial(websiteUrl, profile); categore.Profiles.Add(profile); } catch (Exception) { } } models.Add(categore); } catch (Exception) { } } var json = JsonConvert.SerializeObject(models); File.WriteAllText(@"D:\hellocoton.json", json); }