【发布时间】:2011-10-18 05:57:57
【问题描述】:
我正在尝试从另一个 div 类中的 div 类中提取一个 href。我尝试使用的代码 sn-p 的一个示例是:
<div class="productData">
<div class="productTitle">
<a href="https://rads.stackoverflow.com/amzn/click/com/0786866020" rel="nofollow noreferrer"> Fish! A Remarkable Way to Boost Morale and Improve Results</a>
<span class="ptBrand">by <a href="/Stephen-C.-Lundin/e/B001H6UE16">Stephen C. Lundin</a>, <a href="/Harry-Paul/e/B001H9XQJA">Harry Paul</a>, <a href="/John- Christensen/e/B003VKXJ04">John Christensen</a> and Ken Blanchard</span>
<span class="binding"> (<span class="format">Hardcover</span> - Mar. 8, 2000) </span>
</div>
我试图从这个例子中提取内部类 productTitle 但是使用代码:
Document doc = Jsoup.connect(fullST).timeout(10*1000).get();
Element title = doc.getElementById("div.productTitle");
System.out.println(title);
我得到空值。试图提取更高的元素,例如:
Element title = doc.getElementById("div.productData");
我也得到空值。我尝试了许多代码组合,但无法弄清楚从内部 div 类或内部 id 中提取的语法。
任何帮助将不胜感激。
【问题讨论】:
标签: java html-parsing jsoup