Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting test from html...

Status
Not open for further replies.

loosecannon1

Programmer
Feb 19, 2002
55
US
Hi all -

I'm having difficulties extracting the src attribute and value, for image tags, from an html page.

I looked at using substr(), but the OFFSET and LENGTH won't be consistent and I'm not knowledgeable with regexs, so I'm kinda lost...

Basically, how can I extract and store: src="/images/bulletins/customer.bmp"
from the following snippet:

<!-- CODE SNIPPET -->

Thank for the help.

If I'm unclear on anything please let me know.

<p align=&quot;left&quot;>Some paragraph text...<img alt=&quot;Some Title&quot; src=&quot;/images/bulletins/customer.bmp&quot; border=&quot;0&quot;></p>

<!-- END CODE SNIPPET -->
 
Following is the correct snippet...


Basically, how can I extract and store: src=&quot;/images/bulletins/customer.bmp&quot;,
from the following snippet, in a variable:

<!-- CODE SNIPPET -->

<p align=&quot;left&quot;>Some paragraph text...<img alt=&quot;Some Title&quot; src=&quot;/images/bulletins/customer.bmp&quot; border=&quot;0&quot;></p>

<!-- END CODE SNIPPET -->

Thanks

PS Sure would be nice if we could edit our post after we submited it!
 
You could use preview post. ;)

There's gotta be a simpler way with a regex, but if you still want to try substr, you can use the index function - like instr in VB

HTH ;P
 
Code:
#!perl
$str = qq('<p align=&quot;left&quot;>Some paragraph text...
	<img alt=&quot;Some Title&quot; 
	src=&quot;/images/bulletins/customer1.bmp&quot; border=&quot;0&quot;>
	more text 
	<img alt=&quot;another Title&quot; 
	src=&quot;/images/bulletins/customer2.bmp&quot; border=&quot;0&quot;></p>);
	
while ($str =~ /<img.*?src=&quot;(.*?)&quot;.*?>/gis)
    {
    print &quot;Found $1\n&quot;;
    }
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top