Making a bot for a website in C++?

Started by
9 comments, last by frob 7 years, 6 months ago
How could you do this? I'd prefer if the bot was hidden (as in the website isn't visible on the GUI when the bot does its thing)
Advertisement
Well, this sounds bit dodgy.

What website and what does the bot do to the site?

Why should it be hidden?

Finally how does this relate to game development?
Web browsers consist of:

Making HTTP requests
Executing JavaScript
Parsing and rendering HTML/CSS

A bot needs to:

Make HTTP requests
Parse HTML (sometimes)
Execute JavaScript (extremely rarely)

HTTP requests are EXTREMELY simple compared to the other parts. You can find libraries to do this for you. A bot, instead of rendering the HTML for a user, scans the HTML for the data it's interested in instead. There are libraries for parsing HTML if you need them, or you can use plain text or regular expression searches.

OK, I admit I should have included more information

I want to automate the interactive online homeworks at showmyhomework.co.uk - I'm not a lazy kid, I just thought it would be an interesting project

I want it to be hidden so that the interface is cleaner

And it doesn't relate to game development, because I put it in the general programming section

Web browsers consist of:

Making HTTP requests
Executing JavaScript
Parsing and rendering HTML/CSS

A bot needs to:

Make HTTP requests
Parse HTML (sometimes)
Execute JavaScript (extremely rarely)

HTTP requests are EXTREMELY simple compared to the other parts. You can find libraries to do this for you. A bot, instead of rendering the HTML for a user, scans the HTML for the data it's interested in instead. There are libraries for parsing HTML if you need them, or you can use plain text or regular expression searches.

Ok thanks.

A bit more about what you'll need to understand to make a bot for modern web pages:

Interactive web pages are divided into two parts: The part that is downloaded onto your computer (HTML, CSS, javascript) and the part that runs on the web server (the language used on the server side doesn't matter to you because the two sides use a standard method of communication: HTTP).

When you've got an interactive web page, typically what happens is the javascript running on your machine makes requests to the server to transfer data, and then modifies what's being drawn in the browser GUI. Every web page is different. These are the requests that you will need to automate with your bot. In order to find out how those requests work, you will need to analyze the requests being sent. Most browsers come with a built-in set of debugging tools which will let you watch the requests being made.

After you figure out how the requests work, all you need to do is write a program which understands the possible requests that you can make, how to read the data that the server sends to you, and how to send data back to the server.

The most common type of request you'll have to deal with is logging in. Typically you send some credentials in a request, and the server responds with a session token. From then on, you make each subsequent request using that session token.

You may also need to handle cookies. Cookies are similar to session tokens: The server will occasionally give you a cookie, you need to save it on your machine somehow, and then send that cookie with each request after that.

At that point, the rest of the program is entirely up to you to decide on.

Google for C++ Common Gateway Interface


CGI is a server mechanism, not a client mechanism. If I understand OP correctly, they want to automate interacting with an existing hosted site.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

It's pretty trivial in any framework that has good HTTP and HTML libraries. I write my web automation tools in C#, for example. I use the HtmlAgilityPack and .Net's built in Http classes.

This topic is closed to new replies.

Advertisement