Click here to Skip to main content
16,017,100 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
<div class="image-wrapper">
<img src="http://img6a.flixcart.com/image/book/2/9/9/essential-english-grammar-murphy-400x400-imadbjz55tzgmnr9.jpeg" onload="img_onload(this);"  önerror="img_onerror(this);" data-pid="9788175960299" data-imagesize="pp_main_new" data-error-url="http://img1a.flixcart.com/img/book.jpg" class="small_image product-image imageZoom " alt="Buy Essential English Grammar: A Self-Study Reference and Practice Book for Elementary Students of English with Answers 2nd Edition: Book" title="Essential English Grammar: A Self-Study Reference and Practice Book for Elementary Students of English with Answers 2nd Edition: Book" id="visible-image-small" rel="IMADBJZ55TZGMNR9" data-zoom-src="">
</div>


i want to take only:
http://img6a.flixcart.com/image/book/2/9/9/essential-english-grammar-murphy-400x400-imadbjz55tzgmnr9.jpeg

from the string

i have
C#
string get_image_path = @"<div class='image-wrapper'><img src=(.*?) önload=""img_onload(this)""";
            Regex myRegex = new Regex(get_image_path, RegexOptions.Singleline);
            string image_path = myRegex.Match(result).Groups[1].Value;
            return image_path;


but i am not getting value i am getting null
help me
thanks
Posted

Well, I'm not surprised - your regex doesn't match your input...
Your class delimiters are not the same - double quote and single quote are not the same character; "onload" is not the same as "önload"; there is a semicolon at the end of "img_onload(this);" instead of after the double quote, and so forth.

Seriously, I wouldn't parse HTML with a regex: it's a silly idea. Instead try using a HTML reader which will process the input as HTML and provide lines, attributes, and so forth in a much mopre friendly and reliable way.

A quick google will find you loads of them here: https://www.google.co.uk/search?q=HTML+reader+codeproject&oq=HTML+reader+codeproject&aqs=chrome..69i57j0l5.6613j0j7&sourceid=chrome&espv=210&es_sm=93&ie=UTF-8[^]
 
Share this answer
 
You can go for jQuery also. For example you can check it using the code snippet:

C#
alert($("#visible-image-small").attr("src"));
 
Share this answer
 
Comments
Member 9654996 11-Feb-14 1:12am    
i am not using jquery
Try this

C#
int srcindex = s.IndexOf("src=") -4;
           int onloadindex = s.IndexOf("onload=");
           int length = onloadindex - srcindex -2;
           string output = s.Substring(srcindex, length);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900