Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

how to load url asynchronusly in javafx browser?

 
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im making a crawler application to download news from all epapers
so i want to load the url asynchronously as after loading one url in window the task of downloading show complete than only second url should load which im getting from json.
this is my complete code of application
im loading source url in first window and second window im trying to load url that im getting from json
and in third window i have to save function after finishing load in second window so i have to load url one by one (asynchronous) so that till that the second url should wait till the first url complete its task.
 
Saloon Keeper
Posts: 5878
147
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's a crawler, why do you want the app to have a GUI? The user will look at just a single web page at any given time anyway. If you want to load several pages simultaneously, you can create a CardLayout for each page, and embed webview components in every one. Just make sure they run in different threads.
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its a company requirement.
 
Tim Moores
Saloon Keeper
Posts: 5878
147
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. As a software engineer, you need to learn to push back in strange requirements, though. Anyway, you got your answer.
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya i know thanks no i dont want to load url simultaneously. i want it asynchronously that the url which i decode from json should load one by one asone url complete it task than other should load.
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why i should create cardlayout for every url one url should load at a time and then after first url completes its work than only other should load.
 
Tim Moores
Saloon Keeper
Posts: 5878
147
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So when you said "asynchronously", you actually meant "synchronously"? Because that's what it means when you load one after the other.

Regarding CardLayout: I assumed that you wanted to display the web pages; not so? If not, then what is the purpose of using the JavaFX WebView?
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i want to display web pages only but one after another in second webview.
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes sry synchronously
 
Tim Moores
Saloon Keeper
Posts: 5878
147
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what is the actual problem you're facing? You say you want to have two webviews for two web pages. If you want to load them one after another, check out the WebEngine.getLoadWorker method- it allows you to get access to the class that loads the web page, so you can check its status, and start the 2nd download after the first one has finished.
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one webview only not two in webview when the task of first url completed load second and so on.
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

this is json from which im extracting url and load url one by one in one webview.
 
Tim Moores
Saloon Keeper
Posts: 5878
147
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So no user will actually look at this, it will just load one web page after another? It makes no sense to use a GUI for this, then - what is the actual purpose of downloading the pages? Why is a non-GUI tool like HtmlUnit not better for this? Please give a technical reason, not something like "my manager told me so".
 
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One reason something like WebView may be better than something like HtmlUnit is that WebView is a full browser environment, so it will execute any javascript or stuff related to html5 extensions to Java which something like HtmlUnit will not do.  If the page is loading stuff with Ajax or dynamically adding stuff to the HTML DOM using JavaScript, which is pretty common nowadays for a lot of sites, then WebView would correctly render this to create the DOM, but HtmlUnit would not.  If the purpose is to create something like a library of reasonably accurate screenshots of rendered pages, the WebView would be reasonable for that, but HtmlUnit would not.  However... I have no idea what Niti is really trying to do, so I couldn't say whether one approach or the other would be helpful for Niti or not...
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
specifically i have to load the url one by one in webview than after that i will get the html of that page which i need to  post in other url i hope you understand yes john you are some what right.
 
Niti Kapoor
Ranch Hand
Posts: 407
 
Tim Moores
Saloon Keeper
Posts: 5878
147
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

John Damien Smith wrote:If the page is loading stuff with Ajax or dynamically adding stuff to the HTML DOM using JavaScript, which is pretty common nowadays for a lot of sites, then WebView would correctly render this to create the DOM, but HtmlUnit would not.


Why wouldn't it do that? HtmlUnit supports quite a few JavaScript libraries, especially jQuery, and has no principal problems executing JavaScript.

Of course, if some content is loaded only after some user interaction, then automation with HtmlUnit would be trickier. But in that case, using the JavaFX WebView wouldn't help either (unless a user sits in front of it, and indicates to the app at which point the page is at a state where it should be saved). But I agree, it's bit hard to tell, as the problem statement is not clear on that point.
 
John Damien Smith
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Why wouldn't it do that? HtmlUnit supports quite a few JavaScript libraries, especially jQuery, and has no principal problems executing JavaScript.

I probably should have looked into HtmlUnit a bit more closely before posting earlier, as I didn't know that :-).  Based upon what you write, HtmlUnit would likely suffice for many tasks.  My guess (and it is only a guess) is that WebView might be a bit more functional and compatible  than HtmlUnit as far as implementation of html5 style features, because WebView is based upon a WebKit implementation which has likely undergone more extensive compatibility testing against the html5 specs and various websites than HtmlUnit.  But yes, both approaches would probably be fine depending upon the actual application required.  HtmlUnit would probably be preferred if you wanted to do evaluation and testing of the page load results because I think it was created to directly support those kind of scenarios.  WebView would be good if you want an actual rendering that you can snapshot to an image or something like that.
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its just like a web crawler.
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

im able to load the url but the last url in webview but i want toi load from starting one by one basically the flow is when the url is loaded than i will click on downloaded button and downloads each URL html
waits for download to complete

fires save function when download complete

save function
save_url=http://mms.bulksms101.com/api/crawler/server/ID

replaces ID in url from source
puts or posts
content=download body
meta=headers in json format
and gui we need is because everyday they want to work on that as url will changes everyday so  for rectifying its easy to view on gui hope this time you understand
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
browser1 - url will load one by one browser 2 html will download and browser3- downloaded html will post to the url http://mms.bulksms101.com/api/crawler/server/ID
with id of the url in json
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thecode is running but at end im getting exception



how to send in key value pair as now im post in text/plain but i have send like in content the hml part and in meta  in meta part
 
Rancher
Posts: 4322
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

At this point the value of quanity is not a full URL.
Print it out to see what value it holds.

Indeed, looking at the code, you are printing it out on line 73, so just check your logs.
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i had solve the problem just the problem is content is a array and meta is also an array which in need to post in content = html body meta = headers in json format how can i do so please help.
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
https://inapi.ankiti.com/api/mms.bulksms101.com/crawler/server/138a28186fff71a6997aab9fa2a1a355 this is url in which i had to post in content
json in url
{"data":null,"errors":["content or meta missing in POST or PUT"],"meta":""}
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as i had make simple code to understand can you tell me why the complete string is nt post in url at one it is break in to small small parts
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the ouput
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i had solve this problem but i need outer html
 
Sheriff
Posts: 6366
172
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i had solve this problem but i need outer html  


Are you talking about the outerHTML() method in JavaScript?  What is "outer html"?
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes exactly that is outer html() like in js or you can see any website when you inspect it you will see html tags which are not present in view source of that page i hope you can understand
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
document.body.outerhtml() how can we use in jsoup in java
 
Knute Snortum
Sheriff
Posts: 6366
172
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Niti Kapoor wrote:i hope you can understand


I don't unfortunately.

document.body.outerhtml() how can we use in jsoup in java


It looks like you are using a third party library from https://jsoup.org/ I would suggest that you go there to look for documentation.
 
Your buns are mine! But you can have this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!