Results 1 to 4 of 4

Thread: Download Page Source of Website

  1. #1
    Join Date
    Mar 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Download Page Source of Website

    Hello. I took a class last semester that used Qt and have wanted to explore and continue to use it. I had an idea for a program that I would like to write that would involve checking a website for certain words/phrases when the program is executed. I have looked through the Qt Documentation and come close to what I need in order to make it happen, but I hit a snag.

    The QHttp class has a "get" function that can retrieve the Page Source code from a website and store it to a local file on the computer. Qt even has an example program that does just that. However, the get function only accepts what it calls an "absolute path," which ends with a .com, .html, etc. How would I go about doing the same thing with a relative path with more characters that follow those endings, such as this?

    I am using Linux Ubuntu 9.04 and Qt version 4.5.0. I would also like to be able to compile the program on Windows XP.

    Thank you for your time and help.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Download Page Source of Website

    You would have to convert your relative path to an absolute path before passing it to the function.

    However, your example that you posted ("such as this') is an absolute, not a relative.

  3. #3
    Join Date
    Mar 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Download Page Source of Website

    Thank you, that is true. The problem I am experiencing is that when I use the get function on the example URL, it only "gets" (downloads and stores the page source code of) the first part of the URL: http://foodpro.studentprograms.vt.ed...3/pickMenu.asp
    and ignores the rest:
    ?locationNum=15&locationName=D2+%26+DXPRESS&dtdate =3%2F15%2F2010&mealName=Lunch&sName=Virginia+Tech+ Culinary+Services

    It seems that the second part are some type of "variables" being provided to the website (I don't know the web development lingo) as a result of a couple clicks on the site. Is there some way to pass them to the get function? Or is there some other function to accomplish the same task? I don't necessarily need to use the get function in the QHttp class - it just seemed like the closest thing to what I needed.

  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: Download Page Source of Website

    The part of the URL following the '?' onward is the query string and is one way of passing parameters to a web page generating script.

    The demo program is deliberately ignoring that portion in the code:
    Qt Code:
    1. void HttpWindow::downloadFile()
    2. {
    3. ...
    4.  
    5. QByteArray path = QUrl::toPercentEncoding(url.path(), "!$&'()*+,;=:@/");
    6. if (path.isEmpty())
    7. path = "/";
    8. httpGetId = http->get(path, file);
    9. ...
    10. }
    To copy to clipboard, switch view to plain text mode 
    It uses only the path component of the URL rather than the whole URL. Have a look at the docs for QUrl for more about the components of the URL and how to access them.

Similar Threads

  1. Replies: 3
    Last Post: 17th February 2010, 12:26
  2. Download Source Code
    By psih128 in forum Newbie
    Replies: 3
    Last Post: 6th July 2009, 10:01
  3. Download a web page to utf8.
    By Faster in forum Newbie
    Replies: 2
    Last Post: 13th April 2009, 20:49
  4. Download a web page!
    By Faster in forum Newbie
    Replies: 0
    Last Post: 12th April 2009, 13:35
  5. Read the source page of url? SOLVED
    By triperzonak in forum Qt Programming
    Replies: 0
    Last Post: 19th September 2008, 09:44

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
  •  
Qt is a trademark of The Qt Company.