Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to access data from web
Albert Huert last edited by
I am doing a program to calculate my electric power payment, for this I need to obtain the cost per kWh from the official website of the company that offers the service. I need to enter my username and password to see the cost of kWh in my area. From what I have investigated, I understand that the page file is downloaded in xml format and with a function that file is read to find the required data. How do I connect to your website and get the cost of kWh data?
Thanks for help me.
It depends on how the site logs in etc but normally you can use
Not complete code!
And it might not be called username and password for your site.
You have to check the code for it in a browser or other tool.
QUrl serviceUrl = QUrl("http://test.com/login.php"); QNetworkAccessManager *networkManager = new QNetworkAccessManager(this); connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(serviceRequestFinished(QNetworkReply*))); QUrlQuery postData; postData.addQueryItem("username", "my_username"); postData.addQueryItem("password", "my_password");
Do note QNetworkAccessManager is async and you must use the signals to know when its
finished to login and then try to download the file.
Also if its HTTPS, you might need to download OpenSSL libs to use with your app.
Also, if the site redirects you, you might also get issues/ need to handle that.
Kent-Dorfman last edited by
Sounds like your power company offers a web services interface. There are several flavors, but you'll need to figure out which type your company provides and then use a proper web services API to access their site. It's been my experience that trying to brute force hack the interface doesn't work. So to be clear, this is a level above QNetworkManager, instead using a proper web services API, as determined by which flavor the service provides.
Albert Huert last edited by
@Kent-Dorfman Hi, I think I explained badly, it's not about hacking a website. What I want to do is enter through a program in Qt to the website of the company that gives me the electric power service to check my kWh consumption and what I have to pay. I can do this through a web browser by logging into my account (username + password) and viewing the kWh and payment data in the web browser or I can download an xml file that has this data. What I want is for the program in Qt to enter my password and user and download the xml and me of the kWh to calculate my payment.
That's what is talked about. From my understanding with your second description is that you seem to want to automate a web site usage. What other people proposed here was about using an API provided by your electricity company. If such an API is available, it would likely be easier to implement your application.
Otherwise it seems you want to implement something like selenium, isn't it ?
adomanim Banned last edited by adomanim
This post is deleted!