Clarification about how I should view Forms. What are they?

I have no formal training.

I had originally started out with a console application to scrape the web for prices. After a while, the website I was trying to scrape returned a page stating I needed javascript to view the page. After that I turned to a Forms application so that I could have a JavaScript execution environment.

As I'm looking at the starting template, Program.cs is the entry point and the Form is initialized in Main().

Idk, everything works, but it's not pretty. I'm sure it's because I'm not thinking about this with the right approach.

Here is part of the form (stripped to a point where I hope information isn't invasive)

namespace AutomatedBrowser { public partial class Form1 : Form { public Form1() { Form1 form = this; InitializeComponent(); var html = new HtmlAgilityPack.HtmlDocument(); List<string> websites = new List<string>(); websites.Add(";); List<string> searchFor = new List<string>(); searchFor.Add("turkey"); searchFor.Add("chicken"); searchFor.Add("salmon"); foreach( string x in websites) { foreach( string y in searchFor) { this.webBrowser1.Navigate(x + y); webBrowser1.DocumentCompleted += (s, e) => System.IO.File.AppendAllText("output.txt", webBrowser1.Document.Body.InnerHtml.ToString()); } } } //public static void searchWebsite1(string query) //{ // form.webBrowser1.Navigate(";); // form.webBrowser1.DocumentCompleted += (s, e) => // { // System.IO.File.WriteAllText("HEB.txt", webBrowser1.Document.Body.InnerHtml.ToString()); // }; //} //void completed(object sender, WebBrowserDocumentCompletedEventArgs e) //{ // System.IO.File.WriteAllText(@"output.txt", this.webBrowser1.Document.Body.ToString()); // return; //} } } 

by participationNTroll via /r/csharp

Leave a Reply