in reply to Re: Grabbing url from iframe
in thread Grabbing url from iframe

Yes, sorry I guess strip isn't the right term. I'd prefer to reduce the width and height but that seems like more of a hassle so I thought I'd simply show a graphic in place of the video on the mobile site, and provide a link to the YouTube version. Therefore, I need to be able to strip out the url. I tried to adapt this code, but I'm not having much luck.
my $video = $video; my @parts = split /\<iframe(.+)src=\"/http(.+)/\"(.+)\<\/iframe\>/, $v +ideo; (my $video )= $parts[-2] =~ m/(\d+)/;
This may not be the right way to do this at all but... Thanks.

Replies are listed 'Best First'.
Re^3: Grabbing url from iframe
by ikegami (Patriarch) on Feb 12, 2011 at 05:34 UTC

    The approach is fundamentally bad. You're using split, but you don't have a separated list of things to split on.

    Either option you choose, you need to

    1. Parse the HTML
    2. Locate the elements
    3. Modify the elements
    4. Regenerate the HTML

    In this case, that can all be done by one substitution.

    s/ (<iframe [ ]title="YouTube[ ]video[ ]player" [ ]width=")([0-9]+)(" [ ]height=")([0-9]+)(" ) / $1 . "320" . $3 . ( (320/$2)*$4 ) . $5 /xeg
      Thanks for this. Here's what I have:
      $video =~ s/ (<iframe [ ]title="YouTube[ ]video[ ]player" [ ]width=")([0-9]+)(" [ ]height=")([0-9]+)(" ) / $1 . "320" . $3 . ( (320/$2)*$4 ) . $5 /xeg;
      But it's returning this error:
      Scalar found where operator expected at mobile.pl line 296, near "$1 . + "320" . $3 . ( (320/$2" (Might be a runaway multi-line // string starting on line 289) (Missing operator before $2?) syntax error at mobile.pl line 296, near "$1 . "320" . $3 . ( (320/$2"
      Am I missing something?

        You delimit your regular expression using /, but the replacement part also contains a /. That's unfortunate. Use a different separator for the regular expression, for example !:

        $video =~ s!... !... !xeg;