QWebEnginePage::runJavaScript() doesn't work on an offline page.
Unsolved
QtWebEngine
-
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; }); }