Results 1 to 4 of 4

Thread: How to get the "URL" used in style sheets of a HTML response?

  1. #1
    Join Date
    Oct 2015
    Posts
    3
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Default How to get the "URL" used in style sheets of a HTML response?

    Hello All,

    I'm using qt-webkit to make http/https request and process the html response of it. I want to parse the style sheets present in the HTML response to get the specific elements of style sheets.
    e.g. I have following web page received after HTTP request:

    Qt Code:
    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <style>
    5. body {
    6. background-image: url("http://www.w3schools.com/css/border.png"), url("img_flwr.gif");
    7. background-color: #cccccc;
    8.  
    9. }
    10. div {
    11. cursor: url(http://i.imgur.com/jto5jnA.gif), auto;
    12. }
    13. </style>
    14. </head>
    15. <body>
    16. <div>
    17. this is text
    18. </div>
    19. </body>
    20. </html>
    To copy to clipboard, switch view to plain text mode 


    Now from above HTML response, I want to parse the style sheet and the get the "URL" used. e.g. URL used for "background-image" or "cursor".
    Any pointer on how to get these URLs used in style-sheet?

  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: How to get the "URL" used in style sheets of a HTML response?

    You could use the QWebFrame functions to find all the style elements and then use a regular expression to find strings matching: url\s*\(\s*"[^"]*"\s*\)
    Or something like that in the text of the style element. You may need to allow for both single and double quotes.

  3. #3
    Join Date
    Oct 2015
    Posts
    3
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How to get the "URL" used in style sheets of a HTML response?

    Thanks ChrisW67, but do we get the "style" elements which are present in the HEAD of document as mentioned in the example in above question?

  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: How to get the "URL" used in style sheets of a HTML response?

    I don't see why you wouldn't with a selector of "style" or "head style". Have you actually tried it to see?

Similar Threads

  1. Replies: 3
    Last Post: 16th March 2015, 08:31
  2. Replies: 0
    Last Post: 6th December 2012, 17:54
  3. Qt supported html subset "table" element RTL problem
    By kalma in forum Qt Programming
    Replies: 0
    Last Post: 8th March 2012, 06:19
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 20:05
  5. QWidget pixmap AFTER displaying html ("rich text")
    By gavrilo princep in forum Newbie
    Replies: 0
    Last Post: 17th July 2007, 02:59

Tags for this Thread

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.