SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Parse HTML using CSS Selectors?

    Hi, I was wondering if a php class exists that allows me to extract html elements using css selectors. Currently, what I do is send the html to the browser and use javascript to parse the file, but I would prefer to do this processing on the server.

    Thanks!

  2. #2
    SitePoint Addict dbr's Avatar
    Join Date
    Aug 2006
    Location
    Tucked away in the mountains...
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not exactly what you're trying to accomplish here, but it sounds like you might want to explore using regular-expressions. http://www.regular-expressions.info/php.html
    A little more info could be helpful...

    Posting this in the PHP forum might also get you a better answer quicker...
    Last edited by dbr; Jan 21, 2008 at 20:18. Reason: add more
    "Three components make an entrepreneur:
    the person, the idea, and the resources to make it happen."
    Anita Roddick ~British entrepreneur
    dbr founder of: ProximityCast.com

  3. #3
    SitePoint Member
    Join Date
    Jan 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help, but I know regular expressions. I found that using css selectors is more suitable for parsing html. Some JavaScript libraries (cssQuery, jQuery, YUI, etc.) have methods where you can select certain elements in the dom.

    For example select('table.info a') would select all elements with tag 'a' (which means all hyperlinks) that are descendants (contained in) a table with a class 'info'. In a way, I'm using the built-in html parsing abilities of the browser. The problem is that this relies on the client's web browser and I would like to move this to the server side.

    I did some cursory google searching and couldn't find anything maybe such a server-side alternative doesn't exist.

    Thanks again!

    By the way, I didn't realize I posted it in the non-php forum. Is there a way I could move it?

  4. #4
    SitePoint Addict dbr's Avatar
    Join Date
    Aug 2006
    Location
    Tucked away in the mountains...
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vendiddy View Post
    By the way, I didn't realize I posted it in the non-php forum. Is there a way I could move it?
    Admin has the ability to move a thread. It might be just as easy to simply repost your question over there.
    I don't have a clear vision on what you are attempting to accomplish. I can however appreciate the need or desire to accomplish some things on the server side.
    I found this link when I did a google search: http://css.maxdesign.com.au/selectutorial/
    If you find a solution, I hope you let us hear about it.
    Best of luck!
    "Three components make an entrepreneur:
    the person, the idea, and the resources to make it happen."
    Anita Roddick ~British entrepreneur
    dbr founder of: ProximityCast.com


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
  •