Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. QWebEnginePage::runJavaScript() doesn't work on an offline page.
Forum Updated to NodeBB v4.3 + New Features

QWebEnginePage::runJavaScript() doesn't work on an offline page.

Scheduled Pinned Locked Moved Unsolved QtWebEngine
2 Posts 2 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ayanda83
    wrote on last edited by ayanda83
    #1

    Hi there guys, compliments of the season. I have a very a small problem and I hope this is where I will find assistance. I'm creating this web crawler that mines data off websites. Here is my problem, I am using QNAM to pull the HTML from a website and then I create a QWebEnginePage object where I set the HTML for the purpose of using the QWebEnginePage::runJavaScript() to extract the data I need from the HTML. The problem is that the QWebEnginePage::runJavaScript() function doesn't work if my webpage is in offline mode. The same javascript code works just fine if I run it on an online page. What could be the problem?

    //The two lines of code below are in my constractor.
    page = new QWebEnginePage(this);
    connect(page, &QWebEnginePage::loadFinished, this, &CPT_Page::extract_tender_table);
    
    void CPT_Page::createPage(QStringList linksList)
    {
        QFile tempFile(QDir::currentPath().append("/Include/Program_Files/tenderMainPage.txt"));
    
        if(!tempFile.open(QFile::ReadOnly | QFile::Text))
            qDebug() << "File did not open" << endl;
    
        QByteArray byteArr = tempFile.readAll();
    
        page->setHtml(byteArr);
        QWebEngineView *view = new QWebEngineView();
        view->setPage(page);
        view->show();
    }
    
    //HTML finished loading to page slot.
    void CPT_Page::extract_tender_table()
    {
        page->runJavaScript("function retriev_main_table(){"
                            "var x = document.getElementById(\"rfqsTable\").innerHTML;"
                            "return x;"
                            "}"
                            "retriev_main_table();", [&](const QVariant &data){
            qDebug() << data.toString() <<endl;
            });
    }
    
    
    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bui Trung
      wrote on last edited by
      #2

      Can your page show content when using page->setHtml(byteArr); ?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved