Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JavaFX
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Liutauras Vilda
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
JavaFX
How to iterate DOM in JavaFX and find img and src tags?
Niti Kapoor
Ranch Hand
Posts: 407
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package imagesget; import java.io.StringWriter; import java.util.logging.Level; import java.util.logging.Logger; import javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.concurrent.Worker; import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; import javafx.scene.web.WebEngine; import javafx.scene.web.WebView; import javafx.stage.Stage; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; import org.w3c.dom.NodeList; /** * * @author biznis */ /** * * @author biznis */ public class ImagesGet extends Application { /** * @param args the command line arguments */ @Override public void start(Stage primaryStage) throws Exception { StackPane root = new StackPane(); // create a HBox to hold 2 vboxes HBox hbox = new HBox(10); // create a vbox with a textarea that grows vertically // HBox vbox = new VBox(10); //Label label1 = new Label(""); final WebView browser = new WebView(); final WebEngine wb = browser.getEngine(); //grid.add(new Label("Input Url: "), 0, 0); // grid.add(notification, 1, 0); wb.load("http://epaper.timesgroup.com/Olive/ODN/TheEconomicTimes/#"); wb.getLoadWorker().stateProperty().addListener( new ChangeListener<Worker.State>() { @Override public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) { if (newState == Worker.State.SUCCEEDED) { Document doc = wb.getDocument(); try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); StringWriter stringWriter = new StringWriter(); try { transformer.transform(new DOMSource(doc), new StreamResult(stringWriter)); } catch (TransformerException ex) { Logger.getLogger(ImagesGet.class.getName()).log(Level.SEVERE, null, ex); } String xml1 = stringWriter.getBuffer().toString(); System.out.println(xml1); NodeList anchors = doc.getElementsByTagName("img"); System.out.println(anchors); }catch (TransformerConfigurationException ex) { Logger.getLogger(ImagesGet.class.getName()).log(Level.SEVERE, null, ex); } } } }); } public static void main(String[] args) { Application.launch(args); } }
this is code NodeList anchors = doc.getElementsByTagName("img");
System.out.println(anchors); by finding this im getting
com.sun.webkit.dom.NodeListImpl@614d6ab6 how to get img tag
Tim Moores
Bartender
Posts: 7645
178
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The nodes should have methods to examine their name and other attributes. Check the javadocs to see what's available.
Niti Kapoor
Ranch Hand
Posts: 407
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
i can find this only ElementByTagName.
Tim Moores
Bartender
Posts: 7645
178
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
It may be in a superclass (or super interface) of Node. I don't have access to javadocs, so can't check it myself. Keep looking and trying things out.
Niti Kapoor
Ranch Hand
Posts: 407
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
no im nt able to find?
Niti Kapoor
Ranch Hand
Posts: 407
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
can we access page local cache in
java
.
Niti Kapoor
Ranch Hand
Posts: 407
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
NodeList nList = doc.getElementsByTagName("img"); for (int i = 0; i < nList.getLength(); i++) { Node node = nList.item(i); // if (node.getNodeType() == Element.ELEMENT_NODE) { Element eElement = (Element) node; System.out.println(eElement.getAttribute("src")); // } }
im able to find src like this but without domain name so how can i download the img in local as in java can we access local cache of page ?
Tim Moores
Bartender
Posts: 7645
178
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You know which domain and URL the page came from, so
you should
be able to construct the image URL, no?
Police line, do not cross. Well, this tiny ad can go through:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to read input field and load in webview?
how to break up url in java?
how to load url asynchronusly in javafx browser?
How can I read an image from URL?
button clicked event question
More...