0

I want to be able to get the src image from this html. At first I was thinking regex patern and matcher but I can't seem to figure out how do I get it. I operate on JAVA.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<body class="calibre">
<div class="calibre1">
<div class="s">
<p class="calibre2">
<img class="calibre3" src="0001.jpg"/>
</p>
<br id="calibre_pb_0" class="calibre4"/>
</div>
</div>
</body>
</html>

String a; Output : a = "src="0001.jpg""

Juju
  • 70
  • 8

6 Answers6

1

check out the solution for a more generalized question, try to adapt the for loop instead to look for what you specifically need: How to get all Images src's of some html

Community
  • 1
  • 1
AGE
  • 3,604
  • 3
  • 35
  • 58
1

With jQuery you can use the following to get src on click

$("img").click(function() {
alert($(this).attr('src'));
});

http://jsfiddle.net/n63HE/5/

Philip Kirkbride
  • 19,609
  • 34
  • 109
  • 213
1

The answer to this question was actually really easy. Basic uses of pattern and matcher.

Here is a sample code of how I got the String "src="0001.jpg"".

        Pattern p = Pattern.compile("src=(.*?)/");
        Matcher m = p.matcher(html);
        if(m.find()){
            String item_found = m.group();
            Log.i("Image Found!", item_found);
        }

Again I would like to apologize about forgetting what programming language I use and yes never parse html with regex unless you need to. I just wanted to find a specific item within an html.

Juju
  • 70
  • 8
0

Use an HTML parser or the browser's Document Object Model and get the value from the Attribute interface for the src in "<img class="calibre3" src="0001.jpg"/>".

Mark Cidade
  • 96,194
  • 31
  • 221
  • 232
0

You can use jquery/javascript to get the src of img. I you want to do by such thing then send me reply

Udit Trivedi
  • 246
  • 3
  • 14
0

Why just not using Javascript getElementsByTagName()?

Pier-Alexandre Bouchard
  • 5,045
  • 5
  • 34
  • 71