Android Question Regex.Matcher Issue

hyokim07

Member
Licensed User
Longtime User
Hi, Erel!
I am trying to download image from the web with the following input:
<div class="img"><img id="imgid48" src="image/Kim_Hyo.jpg" alt="Kim_Hyo" width="220" height="220" onClick="toggleIt('id48a')"><div class="desc" id="name48">Kim Hyo</div><div class="desc" id="id48a">?</div></div>

I am trying to use Regex.Matcher. I am lost. Can you please help me?
Thank you very much in advance.
 

hyokim07

Member
Licensed User
Longtime User
This is a community forum. You should not limit your question to a single member...

Which pattern are you trying?
OK, I will be careful next time.
I just want read the pattern of image names. So I can download image images with the different names from the same source.
Thank you in advance.
 
Upvote 0

hyokim07

Member
Licensed User
Longtime User
Thank you, Erel!
I've tried with the following to be able to distinguish with other image files:
Dim m As Matcher = Regex.Matcher(""\"" src=\""([^""]+)\""", text)
Do While m.Find
Log(m.Group(1))
Loop

The results were:
js/floating.js
image/Kim_Hyo.jpg

I just need to get the image file name.

The html file has a several images with different img id.
Is there any way that can extract the bold and underlined one from the below html codes?
<div class="img"><img id="imgid48" src="image/Kim_Hyo.jpg" alt="Kim_Hyo" width="220" height="220" onClick="toggleIt('id48a')"><div class="desc" id="name48">Kim Hyo</div><div class="desc" id="id48a">?</div></div>

<script type="text/javascript" src="js/floating.js"></script>


My desired result should be:
image/Kim_Hyo.jpg

I hope this is not confusing.
Thank you in advance.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Is it YOUR website you want to get the images from or is it an source from domeone other?
If it is yours; you can restructure your html to the desired order inside the img-tag.

If it is from another; you should find the right RegEx for HIS img-tag-propertiers-order. o_O

That´s the problem. You cannot RegEx a Website, you have to use an DOM-Parser...

If it is your website then you also could do that with JavaScript and, if the website is loaded from within a webview with javascript-interface, post the results from Javascript to your App.

With JQuery for ex it should be only a few lines of code...

$('img').each(function(){
var t=$(this);
alert(t.attr('src')); // src
});

Please see this example from warwound telling how to inject javascript into a webpage which is loaded in a webview..
 
Last edited:
Upvote 0

hyokim07

Member
Licensed User
Longtime User
Thank you very much.
I cheated by using the following code and it worked.
Do While m.Find
If (m.Group(1).IndexOf("image")>-1) Then
links.Add(m.Group(1))
End If
Loop
Thanks for all the help.
 
Upvote 0
Top