×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    12

    External Javascript in QWebView

    Hello,

    I am trying to implement screen scraping on some webpages (as the webview kept on throwing panic(bugs have been already reported)).

    I get the form element out of the webview using
    Code:
        QWebView *webView = new QWebView();
        webView->setHtml(htmlStr);
        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)
            {
                break;
            }
        }
    After that i load the form element on to a new webiew and evaluate javascript

    Code:
    QWebView *ftwWebView = new QWebView();
        ftwWebView->setHtml(element.toOuterXml());
        QWebFrame *ftwFrame = ftwWebView->page()->mainFrame();
        result = ftwFrame->evaluateJavaScript("document.getElementById('username').value = 'someusername';");
        result = ftwFrame->evaluateJavaScript("document.getElementById('password').value = 'somepassword';");
        result = ftwFrame->evaluateJavaScript("function include(destination) { var e=window.document.createElement('script'); e.setAttribute('src',destination); window.document.body.appendChild(e); } include('http://somelink.com/somefile.js');");
        result = ftwFrame->evaluateJavaScript("validate_form( document.forms[0], true );");
    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,

    Sri

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2009
    Posts
    1,024

    Re: External Javascript in QWebView

    I think it will work if you use a local file instead of a remote one (http://somelink.com/somefile.js). As far as I know QWebFrame::evaluateJavaScript cannot fetch remote files.

Similar Threads

  1. QWebView
    By atonical in forum Qt
    Replies: 1
    Last Post: 2011-02-13, 19:14
  2. QWebView problem ?
    By damodharan in forum Qt
    Replies: 3
    Last Post: 2010-06-30, 14:25
  3. FAXING_ EXTERNAL SCREEN _ EXTERNAL KEYBOARD _
    By devander in forum General Development Questions
    Replies: 4
    Last Post: 2008-10-24, 16:56
  4. Creating a 6131 readable external tag wth an external reader
    By gngulrajani in forum Near Field Communication
    Replies: 1
    Last Post: 2008-04-03, 17:47

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •