简体   繁体   English

Jsoup选择器的元素之一

[英]Jsoup selector for one of the element

Recently I have started learning jsuop with java where i need to parse html page for properties of an element. 最近,我开始使用Java学习jsuop,在Java中我需要解析html页面以获取元素的属性。 i have took a same page as below . 我的页面如下。 in that there is image when i spy through Selenium IDE i got a property as 当我通过Selenium IDE进行间谍时,有一个图像,我得到了一个属性

 xpath=(//img[@alt='Moto G: Mobile'])[2]

as jsoup does not support xpath. 因为jsoup不支持xpath。 how to convert this in to CSS Selctor for jsoup. 如何将其转换为jsoup的CSS Selctor。

i have tried 我努力了

doc = Jsoup.connect("http://www.flipkart.com/").get();
Elements t3 = doc.select("img[alt='Moto G: Mobile']:nth-of-type(2)");
System.out.println(t3.size());
System.out.println(t3.get(0));

but getting 但是得到

0
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

is there any better way to handle these kind of properties using jsoup. 有没有更好的方法使用jsoup处理这些类型的属性。

can any body help me . 有谁能够帮助我 。

thanks in advance 提前致谢

The Problem is not your query. 问题不是您的查询。 The image you are searching is dynamically added by JavaScript and not part of the HTML you've fetched. 您正在搜索的图像是由JavaScript动态添加的,而不是您获取的HTML的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM