I am trying to use C# to access the content of a webpage. For example, I want to grab the text of the body of google homepage.
I know this is doable in C# with its web browser control. But I couldn't find a good, simple example of doing it. All the resources I found online involve creating Forms and GUI, which I don't need, I just need a good old Console Application.
If anyone can provide a simple console-based code snippet that accomplishes the above, it'll be greatly appreciated.
Yes, although most people won't use C anymore for web development... To use C for web development, you have two options. The first option, called Common Gateway Interface or CGI, is when you're already using some web server software like Apache or IIS.
To use Read Aloud, navigate to the web page you want to read, then click the Read Aloud icon on the Chrome menu. In addition, the shortcut keys ALT-P, ALT-O, ALT-Comma, and ALT-Period can be used to Play/Pause, Stop, Rewind, and Forward.
Actually the WebBrowser is a GUI control used in case you want to visualize a web page (embed and manage Internet Explorer in your windows application). If you just need to get the contents of a web page you could use the WebClient class:
class Program
{
static void Main(string[] args)
{
using (var client = new WebClient())
{
var contents = client.DownloadString("http://www.google.com");
Console.WriteLine(contents);
}
}
}
If you just want the content and not an actual browser, you can use an HttpWebRequest.
Here's a code sample: http://www.c-sharpcorner.com/Forums/ShowMessages.aspx?ThreadID=58261
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With