I was wondering how to extract an image tag and img properties from within an anchor tag?
I know HTMLlinkTag has a linkData() which returns an enumeration, I have tried to convert that to a tag
but I have had no luck.
example of what I am trying to parse
<a href="test"><img src="test"> </a>
I want to get the image tag info.
I appreciate any help.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Gordon
Here's how you can do it - after you recieve the HTMLTag, get its linkData() enumeration, and then downcast to HTMLImageTag.
e.g.
HTMLParser parser = new HTMLParser("http://www.someurl.com");
HTMLNode node,node2;
HTMLLinkTag linkTag;
HTMLImageTag imageTag;
for (Enumeration e= parser.elements();e.hasMoreElements();) {
node = (HTMLNode)e.nextElement();
if (node instanceof HTMLLinkTag) {
linkTag = (HTMLLinkTag)node;
for (Enumeration e2=linkTag.linkData();e2.hasMoreElements();) {
node2 = (HTMLNode)e2.nextElement();
if (node2 instanceof HTMLImageNode) {
imageTag = (HTMLImageTag)node2;
System.out.println("Image loc = "+imageTag.getImageLocation());
}
}
}
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I was wondering how to extract an image tag and img properties from within an anchor tag?
I know HTMLlinkTag has a linkData() which returns an enumeration, I have tried to convert that to a tag
but I have had no luck.
example of what I am trying to parse
<a href="test"><img src="test"> </a>
I want to get the image tag info.
I appreciate any help.
Hi Gordon
Here's how you can do it - after you recieve the HTMLTag, get its linkData() enumeration, and then downcast to HTMLImageTag.
e.g.
HTMLParser parser = new HTMLParser("http://www.someurl.com");
HTMLNode node,node2;
HTMLLinkTag linkTag;
HTMLImageTag imageTag;
for (Enumeration e= parser.elements();e.hasMoreElements();) {
node = (HTMLNode)e.nextElement();
if (node instanceof HTMLLinkTag) {
linkTag = (HTMLLinkTag)node;
for (Enumeration e2=linkTag.linkData();e2.hasMoreElements();) {
node2 = (HTMLNode)e2.nextElement();
if (node2 instanceof HTMLImageNode) {
imageTag = (HTMLImageTag)node2;
System.out.println("Image loc = "+imageTag.getImageLocation());
}
}
}
}
Hmm... code formatting was lost - let me try again
<pre>
HTMLNode node,node2;
HTMLLinkTag linkTag;
HTMLImageTag imageTag;
for (Enumeration e= parser.elements();e.hasMoreElements();) {
node = (HTMLNode)e.nextElement();
if (node instanceof HTMLLinkTag) {
linkTag = (HTMLLinkTag)node;
for (Enumeration e2=linkTag.linkData();e2.hasMoreElements();) {
node2 = (HTMLNode)e2.nextElement();
if (node2 instanceof HTMLImageNode) {
imageTag = (HTMLImageTag)node2;
System.out.println("Image loc ="+imageTag.getImageLocation());
}
}
}
}
</pre>