Тег img пуст в сгенерированном HTML с использованием JavaFX
Я пытаюсь получить HTML-код для поиска на сайте флипкарта с помощью фреймворка JavaFX. Приведенный ниже код работает хорошо, получая мне вывод html, хотя и с небольшим затруднением. Кстати, я использую этот сгенерированный html для просмотра веб-сайта флипкарта. Проблема в том, что файл jpeg, соответствующий продукту, отсутствует в теге изображения для большинства продуктов на html-странице. Я заметил, что для любого продукта в верхних 3–6 продуктах указан тег изображения, в противном случае он будет пустым.
Те, которые имели тег выглядит следующим образом
<DIV class="_3BTv9X" style="height: 240px; width:200px;">
<IMG class="_1Nyybr _30XEf0" alt="" src="https://rukminim1.flixcart.com/image/312/312/mobile/d/f/w/motorola-moto-e3-power-pa4c0009in-original-imaemj7xpcfhnu8r.jpeg?q=70"/>
</DIV>
а те без тега выглядит следующим образом
<DIV class="_3BTv9X" style="height: 240px; width: 200px;">
<IMG class="_1Nyybr" alt=""/>
</DIV>
Ниже приведена программа Java, которая генерирует HTML. Я хотел бы, чтобы кто-нибудь помог мне понять, почему теги изображений пусты и как получить html-страницу с правильными тегами img.
public class Main extends Application {
@Override
public void start(Stage stage) throws Exception {
stage.setTitle("HTML");
stage.setWidth(500);
stage.setHeight(500);
//Scene scene = new Scene(new Group());
//VBox root = new VBox();
final WebView browser = new WebView();
final WebEngine webEngine = browser.getEngine();
webEngine.load("https://www.flipkart.com/search?q=Motorola&otracker=start&as-show=on&as=off");
webEngine.getLoadWorker().stateProperty().addListener((observable, oldState, newState) -> {
if (newState == Worker.State.SUCCEEDED) {
try {
ByteArrayOutputStream b = new ByteArrayOutputStream();
printDocument(webEngine.getDocument(), b);
System.out.println(b.toString());
//FlipkartScrape(b.toString());
Platform.exit();
} catch(Exception e) {
System.out.println("Caught Exception");
Platform.exit();
}
}
});
//webEngine.load(null);
//Hyperlink hpl = new Hyperlink("https://www.flipkart.com");
//root.getChildren().addAll(hpl,browser);
//scene.setRoot(root);
//stage.setScene(scene);
//stage.show();
}
public static void printDocument(Document doc, OutputStream out) throws IOException, TransformerException {
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
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");
transformer.transform(new DOMSource(doc),
new StreamResult(new OutputStreamWriter(out, "UTF-8")));
}
public static void main(String[] args) {
launch(args);
}
public void FlipkartScrape(String html){
org.jsoup.nodes.Document doc = Jsoup.parse(html);
Elements a = doc.select("a[title]");
for (Element next: a) {
Element e;
String title = next.attr("title");
String href = next.attr("href");
href.replaceAll("/", "\\\\/");
if ((e = next.nextElementSibling()) != null) {
e = e.nextElementSibling();
if (e == null)
continue;
e = e.nextElementSibling();
if (e == null)
continue;
} else
continue;
if (href.equalsIgnoreCase(e.attr("href"))) {
href = "http://www.flipkart.com" + href;
System.out.println(title);
System.out.println(e.text());
} else {
e = e.nextElementSibling();
if (e == null) continue;
System.out.println(title);
href = "http://www.flipkart.com" + href;
System.out.println("TEXT"+e.text());
}
Element parent = next.parent();
if (parent != null) {
parent = parent.parent();
if (parent == null) continue;
} else {
continue;
}
e = parent.nextElementSibling();
if (e != null) {
Elements imgs = e.select("img[class]");
for (Element img: imgs) {
String imghref = img.attr("src");
System.out.println("IMAGEHREF"+imghref);
}
}
}
}
}