4

I need to get the content of the meta tag with the name "keywords" from a URL.

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

How can i do this with JSoup?

I have tried getting the element by class, then trying to get the content if the name was keywords, but had no luck:

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

I don't know what I'm doing when it comes to an element without an ID, the error given is pretty straightforward:

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)
3
  • @KickButtowski Yes but it doesn't apply to a tag with no ID so i figured i wouldn't share it. Commented Jul 10, 2014 at 1:50
  • at least post up more info so we can learn more and help you to solve your issue faster? if you have any error you should post it up too :) Commented Jul 10, 2014 at 1:51
  • could you please post up the error too? Commented Jul 10, 2014 at 1:53

1 Answer 1

4

change

document.select("meta.[name=keywords]") 

to

document.select("meta[name=keywords]")

http://jsoup.org/cookbook/extracting-data/selector-syntax

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.