Results 1 to 5 of 5

Thread: read data from website

  1. #1
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default read data from website

    In my website there is a table. I want to read the data from the 1st row 1st column of the table. Please tell me how can I read ? I have my QWebView. Please help. Thanks

    Qt Code:
    1. connect(m_WebView, SIGNAL(loadFinished(bool)), this, SLOT(LoadFinishedCB(bool)));
    2.  
    3. m_WebView->setUrl(QUrl("http://www.mywebsite.com"));
    To copy to clipboard, switch view to plain text mode 

    In LoadFinishedCB I want to read the data. Please help.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: read data from website

    Acess the QWebFrame through your view and then use findFirstElement and related functions to access the QWebElements in the web page

  3. #3
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default Re: read data from website

    Please check the code snippet below. I am trying to click on link in the page twice and then a table is loaded i want to read one data from the table from 1st row and 2nd column. Please help.
    Qt Code:
    1. void MainWindow::LoadFinishedCB(bool ok)
    2. {
    3. QFile file("out.txt");
    4. if (!file.open(QIODevice::WriteOnly))
    5. return;
    6. QTextStream out(&file);
    7. button_click = m_WebView->page()->mainFrame()->documentElement().findAll("a");
    8. qDebug() << button_click.count() << "\n";
    9.  
    10.  
    11. button_click.at(5).evaluateJavaScript(
    12. "var evObj = document.createEvent('MouseEvents');evObj.initEvent( 'click', true, true );this.dispatchEvent(evObj);"
    13. );
    14.  
    15.  
    16. button_click.at(48).evaluateJavaScript(
    17. "var evObj = document.createEvent('MouseEvents');evObj.initEvent( 'click', true, true );this.dispatchEvent(evObj);"
    18. );
    19. //The above piece loads a new link in the same page.
    20. //At this stage how can I make the program to wait till the page is //refreshed ???
    21.  
    22. out << m_WebView->page()->currentFrame()->toHtml() << "\n";
    23.  
    24. QWebElementCollection tables = m_WebView->page()->currentFrame()->findAllElements("table [id=layer_showhost]");
    25. qDebug() << tables.count() << "\n";
    26.  
    27. QWebElementCollection trs = tables.first().document().findAll("tr");
    28. qDebug() << trs.count() << "\n";
    29.  
    30.  
    31. for(int m=0; m<trs.count(); m++)
    32. {
    33. QWebElementCollection tds = trs.at(m).document().findAll("td");
    34. qDebug() << tds.count() << "\n";
    35.  
    36. for(int n=0; n<tds.count(); n++)
    37. {
    38. QWebElementCollection spans = tds.at(n).document().findAll("span");
    39. qDebug() << spans.count() << "\n";
    40.  
    41. for(int z=0; z<spans.count(); z++)
    42. {
    43. out << spans.at(z).document().toPlainText() << " ";
    44. }
    45. }
    46.  
    47. }
    48. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: read data from website

    Does the QWebView (or something else) emit loadStarted() and then loadFinished() in response to clicking on the button?

  5. #5
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default Re: read data from website

    no loadFinished is not being emitted.

Similar Threads

  1. Read data from txt file
    By wiatrak11 in forum Newbie
    Replies: 4
    Last Post: 10th March 2013, 17:50
  2. read output data
    By KillGabio in forum General Programming
    Replies: 4
    Last Post: 6th February 2012, 17:31
  3. Replies: 0
    Last Post: 10th September 2011, 14:38
  4. Read live stock quoted from a website using qt4 c++?
    By abghosh in forum Qt Programming
    Replies: 4
    Last Post: 21st February 2010, 04:08
  5. can`t read a binary data!
    By blm in forum Qt Programming
    Replies: 8
    Last Post: 18th September 2008, 17:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.