I am trying to implement screen scraping on some webpages (as the webview kept on throwing panic(bugs have been already reported)). Using Qt 4.6.3 for Symbian.
I get the form element out of the webview using
- QWebElementCollection formElements = webView->page()->mainFrame()->findAllElements("form");
- QWebElement element;
- for(int i = 0; i < formElements.count(); i++)
- element = formElements.at(i);
- QString attName = element.attribute("name", "-999");
- if(attName.compare("login") == 0)
- QWebFrame *ftwFrame = ftwWebView->page()->mainFrame();
The validate_form function in located in somefile.js file. If i repeat the same steps in browser it works perfectly but QWebView is failing to run the function.
My question is will the webview load functions from external .js files if i load the webview using setHtml instead of loading it from an URL.
Thanks for the reply. I am already doing that
- function include(destination)
- var e=window.document.createElement('script');
The function is in the js file. In the src attribute the url path is also correct but none of the functions get called. I think it is not auto downloading. Is there a way i can initiate it?
I tried it with no luck
I also included this
- ftwWebView->settings()->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, true);
Again with no luck. Can’t QWebView load js functions from the link? Or is it because i am setting setHTML?
This is what i wanted to do:
1) Get a form element out of web-view.
2) Load the contents of the form i.e., username and password.
3) Encrypt the “input” tags wherever necessary using the js functions.
4) Submit the form.
5) Get the cookies of that session.
Initially i tried to open the webview ask the user to enter all the details and then i used to close the webview after taking the cookies. But the webview for some sites used to throw panic on symbian devices. So i took up screen scraping method.
Now to run the JS i could have used QScriptEngine but there were more than 6-7 interlinked JS files.
Thanks for the help and this is the best alternate way i found. But i will continue to search as you mentioned this might not be a correct way.
I load JS files that contain functions into webview frequently using the following method:
- In jsCleared read in the js file that contains your functions. I save my functions in a resource file but you can load in any file from any source (including libraries like jQuery).
This is the simplest method I found for loading js libraries (either internal or external) that I don’t want to be a permanent part of the HTML file.
Note: I use this method with Qt 4.8.1 on a desktop.