static void Main(string[] args) { Scrape myScrape = new Scrape(); string outputString = myScrape.ScrapeWebPage("https://www.atom.io"); Console.WriteLine(outputString); Console.ReadLine(); }
static void Main(string[] args) { Scrape myScrape = new Scrape(); string value = myScrape.ScrapeWebPage("https://duckduckgo.com/"); Console.WriteLine(value); Console.ReadLine(); }
static void Main(string[] args) { Scrape myScrape = new Scrape(); string value = myScrape.ScrapeWebPage("http://msdn.microsoft.com"); Console.WriteLine(value); Console.ReadLine(); }
static void Main(string[] args) { Scrape myScrape = new Scrape(); string reply = myScrape.ScrapeWebPage("https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/file-system/how-to-write-to-a-text-file"); Console.WriteLine(reply); }
static void Main(string[] args) { Scrape myScrape = new Scrape(); //references from MyCodeLibrary string value = myScrape.ScrapeWebPage("https://ois2.ttu.ee/uusois/uus_ois2.tud_leht"); Console.WriteLine(value); Console.ReadLine(); }
static void Main(string[] args) { string websiteUrl = "https://msdn.microsoft.com"; string filepath = @"D:\ITStudying\BobTaborCourse\Lesson17\WriteText2.txt"; Scrape myScrape = new Scrape(); string urlValue = myScrape.ScrapeWebPage(websiteUrl, filepath); Console.WriteLine(urlValue); Console.ReadLine(); }
static void Main(string[] args) { Scrape myScrape = new Scrape(); // string strValue = myScrape.ScrapeWebPage("http://www.msdn.microsoft.com"); string strValue = myScrape.ScrapeWebPage("http://www.google.com"); /* * string strValue = myScrape.ScrapeWebPage("http://www.nike.com"); * - this one fails since the site is expecting authentication before it will let the user scrape the text of the page */ Console.WriteLine(strValue); Console.ReadLine(); }
static void Main(string[] args) { // Example with my own Class Library reference assembly - Within same project. // This means when you add reference, its within the project tab already instead of manually browsing for it! // Solution Explorer -> References -> Add Reference -> Project Tab -> Tick assembly dll -> Win. string kingdavidUrl = "https://kingdavid.xyz"; string beautyUrl = "https://beautyandtheast.com"; string separator = new string('-', 50) + "\n"; Scrape scraper = new Scrape(); scraper.ScrapeWebPageToConsole(kingdavidUrl); Console.WriteLine(separator); string kingdavidContent = scraper.ScrapeWebPage(kingdavidUrl); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("KING DAVID CONSOLE..."); Console.WriteLine(kingdavidContent); Console.WriteLine(separator); string beautyPageContent = scraper.ScrapeWebPage(beautyUrl); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("BEAUTY AND THE EAST STANDARD..."); Console.WriteLine(beautyPageContent); Console.WriteLine(separator); string kingdavidContentFile = scraper.ScrapeWebPageToFile(kingdavidUrl, "/Users/Administrator/Documents/Visual Studio 2017/Projects/C#/Fundamentals-of-C#/ReferencesAndClassesTogether/kingdavid.txt"); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("KING DAVID FILE..."); Console.WriteLine(kingdavidContentFile); Console.WriteLine(separator); //------------------------------------------------------------------------------------------------------------------- // Example with some default reference assembly i.e. System.Net // We had to add the System.Net framework before we can make calls to it - i.e. create an email message // Right click References in Solution Explorer -> Add Reference -> Tick System.Net -> System.Net should appear in Solution Explorer / be available now. MailMessage email = new MailMessage(); email.From = new MailAddress("*****@*****.**"); email.To.Add(new MailAddress("*****@*****.**")); email.Subject = "Test Email C# Fundamentals"; email.Body = "Test Email from C# Fundamentals course! Checking Reference to System.Net is working :)"; SmtpClient client = new SmtpClient(); client.Port = 25; client.EnableSsl = true; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Host = "smtp.gmail.com"; client.Credentials = new System.Net.NetworkCredential("*****@*****.**", @"c01/\/Check2017!"); try { Console.WriteLine("Sending email now..."); client.Send(email); Console.WriteLine("Email sent!"); } catch (Exception e) { Console.WriteLine(e); Console.WriteLine("Email failed to send :(. Please check logs for errors"); } Console.WriteLine("Hit<Enter> or Ctrl - C to exit."); Console.ReadLine(); }
static void Main(string[] args) { /** * Assemblies form the fundamental unit of deployment, version control, reuse, * activation scoping, and security permissions for a .NET-based application. * * Assemblies take the form of an executable (.exe) file or dynamic link library * (.dll) file, and are the building blocks of the .NET Framework. * They provide the common language runtime with the information it needs * to be aware of type implementations. * * You can think of an assembly as a collection of types and resources * that form a logical unit of functionality and are built to work together. */ // Example 1: // site:microsoft.com write to text file c# string text = "A class is the most powerful data type in C#. Like a structure, " + "a class defines the data and behavior of the data type. "; File.WriteAllText(@"C:\code\cshb-school\tmp\WriteText1.txt", text); Console.WriteLine("Writing to a text file... Done"); // Example 2: // sites:microsoft.com c# download html string WebClient client = new WebClient(); string reply = client.DownloadString("https://docs.microsoft.com"); File.WriteAllText(@"C:\code\cshb-school\tmp\WriteText2.txt", reply); Console.WriteLine("Writing to a text file... Done"); // Add a new References to a project: // Example 3: // Add a new Reference to our project // Solution Explorer -> Dependencies -> Add Reference -> ... // Example 4: /** NuGet is the package manager for .NET. * * The NuGet client tools provide the ability to produce and consume packages. * The NuGet Gallery is the central package repository used by all package authors and consumers. */ // Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution // And install Entity Framework, or Boorstrap, and etc! // Example 4: // Create a reusable library // Create a new project and a Class (in this case MyClassLibrary) // Add a new reference (see Example 3) Scrape myScrape = new Scrape(); string value = myScrape.ScrapeWebPage("https://docs.microsoft.com"); Console.WriteLine(value); Console.ReadLine(); }