gsr
05/18/2024, 10:18 AM<cffunction name="fetchDivContent" returnType="any" hint="Fetches and returns the content of a specific div">
<cfargument name="targetUrl" type="string" required="yes" hint="The URL of the page containing the target div">
<cfset var httpResponse = "" >
<cfset var document = "" >
<cfset var divContent = "" >
<cftry>
<!--- Send HTTP request to fetch the page content --->
<cfhttp url="#arguments.targetUrl#" method="GET">
<cfset httpResponse = cfhttp.FileContent>
<!--- Parse the HTML content --->
<cfset document = createObject("java", "org.jsoup.Jsoup").parse(httpResponse)>
<!--- Find the <div> by its class name and extract its inner HTML --->
<cfset divContent = document.select(".table-1").outerHtml()>
<cfcatch type="any">
<cfdump var="#cfcatch#">
<!--- Log error if any occurs during fetching or parsing --->
<cf_log type="error" file="#request.logs#/jsoupFailed.csv" text="#cfcatch.message#" time="#TimeFormat(now(),'long')#" date="#DateFormat(now(),'long')#">
</cfcatch>
</cftry>
<cfreturn divContent>
</cffunction>
but i am getting object initiation error
i had setit tup in application.cfc as:
this.javaSettings = {
loadPaths : [expandPath("./jars")],
loadColdFusionClassPath : true,
reloadOnChange : false,
watchInterval : 100,
watchExtensions : "jar"
};
and also verified that the jar files are in the right pathAdam Cameron
gsr
05/18/2024, 12:37 PM2705 : <cfset var document = "" >
2706 : <cfset var divContent = "" >
2707 : <cfset var jsoup = createObject("java","org.jsoup.Jsoup")>
2708 : <cftry>
2709 : <!--- Send HTTP request to fetch the page content --->sana
05/18/2024, 12:43 PMexpandPath("./jars") just to make sure the files are there.gsr
05/18/2024, 3:20 PMAdam Cameron
loadPaths : [expandPath("./jars")], didn't exist, you'd get a The directory or file [whatevs] specified in LOADPATHS does not exist error, so I'm guessing it's not that.
I'd stick this in yer Application.cfc and see what it says:
writeDump([
dir = expandPath("./jars"),
dirExists = directoryExists(expandPath("./jars")),
files = directoryList(expandPath("./jars"))
])
Does the files bit list the jsoup jar?Adam Cameron
gsr
05/19/2024, 12:20 PMAdam Cameron
/jars rather than ./jars). If CF loads the file at runtime, when the createObject is called, that path might be (incorrectly) interpreted as being relative to the file with the createObject call, not relative to Application.cfc's location?gsr
05/21/2024, 1:17 AMAdam Cameron
gsr
05/21/2024, 3:42 PMgsr
05/21/2024, 3:44 PMsana
05/21/2024, 3:46 PMgsr
05/21/2024, 3:48 PMAdam Cameron
throw "yup"; in the Application.cfc just before the javaSettings, to demonstrate you have that config in the same Application.cfc that's being executed for the code yer running?