Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Extract and modify IMG SRC tags in an HTML document.

by chromatic (Archbishop)
on Apr 27, 2000 at 02:26 UTC ( #9340=note: print w/ replies, xml ) Need Help??


in reply to Extract and modify IMG SRC tags in an HTML document.

If you're willing to invest a few minutes in learning about modules (HTML::Parser and HTML::TokeParser come to mind -- follow the link to CPAN) rather than a few minutes banging your head against the wall figuring out how to catch corner cases with regular expressions, it will pay off greatly.

If all of the HTML is very similar and not too tricky, you can use a regexp like: $line = s!(<img src=")[^"]+([^>]*">)!$1$newimage$2!gi; to do your substitution. Be warned, using regular expressions on HTML is very tricky, unless you're dealing with extremely consistent HTML.


Comment on Re: Extract and modify IMG SRC tags in an HTML document.
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://9340]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-07-10 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (199 votes), past polls