2014-07-10 29 views
4

我需要從URL獲取名稱爲「關鍵字」的元標記的內容Java從JSoup獲取html的字符串列表

<meta name="keywords" content="cat,dog,woof,meow"> 

我怎樣才能做到這一點與JSoup

我試圖獲得通過類元素,然後試圖讓內容如果名稱爲關鍵字,但沒有運氣:

String keywords = document.select("meta.[name=keywords]").get(0).attr("content"); 

我不知道我在做什麼,當談到到沒有ID的元素,給出的誤差是非常簡單的:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: String must not be empty 
    at org.jsoup.helper.Validate.notEmpty(Validate.java:92) 
    at org.jsoup.select.QueryParser.byClass(QueryParser.java:208) 
    at org.jsoup.select.QueryParser.findElements(QueryParser.java:146) 
    at org.jsoup.select.QueryParser.parse(QueryParser.java:65) 
    at org.jsoup.select.QueryParser.parse(QueryParser.java:39) 
    at org.jsoup.select.Selector.<init>(Selector.java:80) 
    at org.jsoup.select.Selector.select(Selector.java:93) 
    at org.jsoup.nodes.Element.select(Element.java:252) 
+0

@KickButtowski是的,但它並不適用於標籤沒有ID,所以我想我會不會分享。 – ThatGuy343

+0

至少發佈了更多信息,以便我們可以瞭解更多信息並幫助您更快地解決您的問題?如果你有任何錯誤,你應該發佈它:) –

+0

你可以請張貼錯誤? –

回答