I want to write a program in C/C++ that will dynamically read a web page and extract information from it. As an example imagine if you wanted to write an application to follow and log an ebay auction. Is there an easy way to grab the web page? A library which provides this functionality? And is there an easy way to parse the page to get the specific data?
Reading a web page with RestSharp We install the RestSharp package. using RestSharp; var client = new RestClient("http://webcode.me"); var request = new RestRequest(); var res = await client. ExecuteGetAsync(request); Console. WriteLine(res.
Here's a basic example: URL url = new URL("http://www.stackoverflow.com"); URLConnection urlConnection = url. openConnection(); InputStream result = urlConnection. getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(result)); String line = null; while ((line = reader.
web page. A document which can be displayed in a web browser such as Firefox, Google Chrome, Opera, Microsoft Internet Explorer or Edge, or Apple's Safari. These are also often called just "pages." website. A collection of web pages which are grouped together and usually connected together in various ways.
Have a look at the cURL library:
#include <stdio.h> #include <curl/curl.h> int main(void) { CURL *curl; CURLcode res; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se"); res = curl_easy_perform(curl); /* always cleanup */ curl_easy_cleanup(curl); } return 0; }
BTW, if C++ is not strictly required. I encourage you to try C# or Java. It is much easier and there is a built-in way.
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