-3
我該如何着手從該標記獲取Questions
文本?如何從源代碼中獲取元素Jsoup
<li>
<a id="nav-questions" href="/questions">Questions</a>
</li>
from https://stackoverflow.com/ source code as a example。
我該如何着手從該標記獲取Questions
文本?如何從源代碼中獲取元素Jsoup
<li>
<a id="nav-questions" href="/questions">Questions</a>
</li>
from https://stackoverflow.com/ source code as a example。
只需選擇你想要的元素,並調用text()
方法就可以得到它生成的文本。
換句話說使用類似
Elements anchors = document.select(cssQuerryForElementsYouWantToFind);
for(Element a : anchors){
System.out.println(a.text());
}
如果您有創建選擇部分cssQuerry麻煩看看http://jsoup.org/cookbook/extracting-data/selector-syntax
你有什麼樣的工具來得到這個文本?如果你使用類似jQuery(或JavaScript)的東西,你可以做$(「#nav-questions」)。html();或.text(); 。您可能想要更具體地瞭解您如何定位此div,具體取決於您在頁面上的內容。 – ajmajmajma