Question

As the title implies,

I need to fetch data from certain website which need logins to use.

The login procedure might need cookies, or sessions.

Do I need QtWebkit, or can I get away with just QNetworkAccessManager?

I have no experience at both, and will start learning as I go. So please save me a bit of time of comparing both ^^

Thank you in advance,

Evan

Edit: Having read some related answers, I'll add some clarifications:

The website in concern does not have an API. So I will need to scrape web elements for the data myself. Can I do that with just QNetworkAccessManager?

Was it helpful?

Solution

No, in most cases you don't need a full simulated web browser. In most cases, just performing the same web requests like a web browser would do is enough.

Try to record the web requests in your browser, using a plugin like "HTTP Live Headers" or "Firebug" in Firefox. I think Chrome provides a similar tool out of the box. These tools record the GET and POST requests done by the website when you send a form in the webpage.

Another option is to inspect the HTML code of the login page. Find the <form> tag and its fields. Put them together in a GET / POST request in your application to simulate the same form.

Remember that some pages use randomized "tokens" in their forms, some set the tokens as cookies. In such cases, you need to request the login page itself in your application first (before sending the filled in form). Both QWebView and QNetworkAccessManager have cookie support.

To sum things up, I think QWebView provides a far more elegant way to simulate user interaction with a web page. The manual way is, however, more "lightweight", as you don't need Webkit and your application might be faster (because only the HTML page is loaded, without any linked resources like images, CSS, javascript files).

OTHER TIPS

QWebView as class name states is a view, so it views something (in this case web pages). If you don't need to display loaded page, then you don't need a view. QNetworkAccessManager may do the work, but you need some knowledge about HTTP protocol, and also anything about target site: how does it hande logins, what type of request you have to send to login etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top