Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I fetch data from a website inside a C++ program

Tags:

c++

I want to write a program in C++ that helps to manage my hockey pool, and one of the key things i will need to do is read off the schedule for the week ahead. I was hoping to use the NHL website. is there any way to have the program download the HTML file for a given url, and then parse that? i suppose that once i have the file downloaded, Simple file I/O would do, but im not sure how to download the file.

like image 689
Ben313 Avatar asked Dec 20 '10 08:12

Ben313


People also ask

Can you do web scraping with C?

As you saw in this tutorial, C++, which is normally used for system programming, also works well for web scraping because of its ability to parse HTTP.

Can you code websites in C?

Can you write a website in C language? Actually, you can. You can use whatever you want on the server as long as the output is HTML, which is sent to the browser. You just put your executable in the CGI-BIN directory and execute it by calling the program from the client.

How is a webpage fetched?

The basic model of page loading on the Web is that your browser makes one or more HTTP requests to the server for the files needed to display the page, and the server responds with the requested files. If you visit another page, the browser requests the new files, and the server responds with them.


1 Answers

Using libcurl is one option. Here is an example of using it with C++ to download contents of a webpage as a string.

like image 152
darioo Avatar answered Sep 16 '22 17:09

darioo