in my code i am calling a url using JAVA ```doc =...
# cfml-general
s
in my code i am calling a url using JAVA
Copy code
doc = Jsoup.connect(arguments.url).get();
now in CF i tried this but still not orking
Copy code
f[1] = expandPath("../jar/jsoup-1.14.3.jar");
            
            obj=createObject("component","jar.javaloader.JavaLoader").init(f);
            Jsoup = obj.create("org.jsoup.Jsoup"); 
var doc = Jsoup.parse(url).body();
but everythingi select is coming as empty
m
I'm not familiar with jsoup, but what is "calling a url" supposed to do? What's the overall objective here?
m
what are you trying to accomplish? to get the doc similar as java, you are still needing to do in cf: doc = Jsoup.connect( url ).get();
r
I'm having no trouble with this:
Copy code
var jsoup = createObject("java", "org.jsoup.Jsoup", "jars/jsoup-1.13.1.jar")
var html = "<html><body>foo</body></html>";
var htmlDoc = jsoup.parse(html);
var body = htmlDoc.select("body");
writeDump(body.toString());
writeDump(body);
abort;
s
what is the error?
are you sure the
jar
is being loaded?
b
Jsoup.parse(url).body()
-
url
is a scope in ColdFusion, so this might be like a struct instead of what you want it to be, which is a string. Something to check.
s
@Simone
s
@Scott Steinbeck i am doing this
Copy code
var doc = getJsoup.parse(iurl); 
            var body = doc.select("body");
           
                 var a= doc.select('[data-e2e="music-video-count"]');
                 writedump(a); abort;
i am getting empty
s
you should at least get a java object back even if its empty
Copy code
doc = getJsoup.connect(iurl).get(); 
writeDump(doc.body().html());
does this output anything?
s
i get a java object and it shows me the methods
but when i try to use select, it throws me an error
Copy code
var a= doc.select('[data-e2e="music-video-count"]');
s
i think the
parse
is where your problem is,
parse
is for a string of html, if your getting data from a url you need to do
Copy code
getJsoup.connect(iurl).get();
s
this is what i am trying
even i removed parse and tried the method u mentioned, i am getting hostname is
Copy code
HTTPS hostname wrong: should be <www.tiktok.com&gt
s
i got this to work on my side
Copy code
Jsoup = createObject("java", "org.jsoup.Jsoup");
	test = Jsoup.connect("<https://www.tiktok.com/music/Rocking-A-Cardigan-in-Atlanta-7058463948324767746?lang=en>").timeout(0).get();
	WriteDump(test.select('[data-e2e="music-video-count"] strong').html());
s
what version of coldfusion and jsoup are u using
i am using latest jsoup and cf2021
s
CF11, not sure what version of jsoup
s
but how u tested
did u installed jsoup directly in the web-inf library and calledu using java
i am using javaloader
s
mine is just via the this.javaSettings in application.cfc
s
can you share the this.JavaSettings Code please
s
Copy code
this.javaSettings = {
		loadPaths              : directorylist( expandPath( '/lib' ), true, 'array', '*jar' ),
		loadColdFusionClassPath: true,
		reloadOnChange         : false
	};
this will add in any .jar files within a
/lib
folder in the root of your project
💯 1
s
let me try this