Question

For some reason, I am always getting an odd result from my select() calls to the jSoup object.

Here is my code (I am trying to get simple title and meta tag values and insert them into my object called 'request'):

<cfset jsoupObject = createObject("component","lib.javaloader.JavaLoader").init([ expandPath('/lib/jsoup-1.7.2.jar') ]) />
<cfset jsoupCreate = jsoupObject.create("org.jsoup.Jsoup") />           
<cfset parsed = jsoupCreate.parse(document.filecontent) />

<cfset variables.request = {} />
<cfset variables.request.title = parsed.select("title").first() />
<cfset variables.request.description = parsed.select("meta[name=description]").first() />

Because I have this in a CFC, I am using a Java Loader, which works fine. document.filecontent is a block of HTML code, which works fine.

When I output my request object I get the following results:

enter image description here

What could be going wrong here?

You can ignore the other keys in the request object, the only ones to note here are description and title, which both give me weird results!

I am loading my HTML via CFHTTP in some code prior to this (all works fine).

I'd really appreciate your help.

Many thanks, Michael.

UPDATE:

Dumping 'parsed' I get the following:

enter image description here

Dumping parsed.select("title") I get:

enter image description here

Was it helpful?

Solution

You're storing the actual Element rather than the content of the tag, which is what I assume you were intending. Even though you'd expect it to dump as a Java object there might be some quirk that's stopping that. You probably want to store the actual text instead of dumping the element though, eg:

<cfset variables.request.title = parsed.select("title").first().text() />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top