1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

[PERL] Regex to pull contents of a div out of a variable?

Discussion in 'Programming' started by Christian Little, Mar 16, 2010.

  1. #1
    Suppose I have a variable called $html which contains an entire webpage worth of HTML code.

    What I want to do is look for this:

    
    <div class="foo">bar</div>
    
    HTML:
    And extract "bar" only from the entire string. There is only 1 div statement that uses that specific class in the entire html code.

    Can somebody point me in the right direction here? I suck at perl regex'ing :(
     
    Christian Little, Mar 16, 2010 IP
  2. Bagi Zoltán

    Bagi Zoltán Well-Known Member

    Messages:
    364
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    110
    #2
    I don't have any knowledge about regexp, but if you have the willingness to use id instead of class regarding to the unique div you may use the document.getElementByid('foo').value javascript function to grab the contained character string.
    Thanks
     
    Bagi Zoltán, Mar 16, 2010 IP
  3. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Can't use javascript I'm afraid. The content is on a third party website, this is essentially scraping a tiny piece of something off one of their pages. I can't inject JS code into their pages to run something like that, and I need the result stored in Perl for some other code that is run.
     
    Christian Little, Mar 16, 2010 IP