Can I display a website like wikipedia, google or etc. in my Java applet? I am looking for something like WebBrowser component in C#. Does anyone know how to achieve this?
Take a look at those two answers:
answer 1
answer 2
There are several browser components, and you can see Best Java/Swing browser component? here on SO for some discussion on the "best".
A thought aside - since an applet is already in a web browser, it might be better to bridge to get the browser to display the website you want in, say, an <iframe>, rather than load a browser into a browser.
Swing supports basic HTML (I think version 2.0 or so). So, you can try to use it.
Also there are a several good pure java fully functional HTML browsers.
The question is: why? Java applet runs into browser that knows to show HTML pages. You can easily cause applet to show HTML page into the native browser where it is running now.
Related
I am working on a little app for myself. I am trying to get a list of links from a site. The site is for example: http://kinox.to/Stream/Prison_Break.html
If you hover over the big window in the middle that says kinox.to best online, it show the link that I want in the bottom left. The problem is if I look at the html file I can't find the link anywhere. I guess it has to do something with the site using JavaScript or Ajax.
Is it possible to somehow get the link using JSoup or are there any other Java libraries that could help me?
I did not look closely into the page you try to load, but here is what I think the problem may be: The link is loaded/generated dynamically via JavaScript. Jsoup does not run JavaScript, so therefore you can't find the link in the html.
Two possible solutions:
1) Use something like selenium webdriver to access the content. The Java bindings allow to remote control a real browser which should have no problems loading the page and running all scripts within. Solution 1 is simple to program, but runs slowly. It may depend on an extern browser program which must be installed on the machine. An alternative to webdriver is the JavaFx webkit engine in case you are on java 8.
2) Analyse the traffic and the JavaScript on the page and find out where the link comes from. This may take a bit of time to find out, but when you succeed you can use Jsoup to get all the data you need. This solution should run much faster than solution 1.
One solution and probably the easiest would be to use Selenium:
WebDriver driver = new FirefoxDriver();
driver.get("http://kinox.to/Stream/Prison_Break.html");
String mylink = driver.findElement(By.cssSelector("#AjaxStream > a")).getText();
I'm working on a way to detect defacement on my website. The idea is to crawl the whole website and for each page, take a screenshot or render the website as an image and compare it with the last time the page has been checked.
I'm looking for a way to convert a whole webpage (HTML, CSS, JS) into an image, like a screenshot, no matter the language is (but I would prefer Java, Python or C#)
I need it to be fast and usable on a server.
I already tried the folowing in Java:
CssBox, but the rendering isn't good enough (no JS)
Selenium Web Driver, but it's way too slow (Time to open firefox, display the page etc...) and not usable without GUI
I think a solution would be a kind of wrapper for a web engine but I didn't find anything about that (at least in Java). I've been told PhantomJS would fit for this need, is it right?
The perfect result would be to create something like that: http://www.page2images.com/home
Use a browser which you can control via a script or command line options like phantomjs. The documentation contains examples how to make screenshots from URLs.
The website you linked offer some good rest API that perform the task: it's not a viable option for you?
Selenium is your best bet. Depending on your page content (ie. JS libraries, etc) it might take some time, but you could automate this with a script to run nightly via cron. Or using screen.
It has a rich language of assertions and simulated mouse events, and ways to regression-test and/or monitor the state of a set of pages.
Good luck.
With no GUI, it's probably not possible to do something like this.
If you're not too tight on the GUI and related things, you can use the JavaFX Webview and take a screenshot of the node using the following code
WritableImage image = webView.snapshot(null, null);
BufferedImage bufferedImage = SwingFXUtils.fromFXImage(image, null);
....
References:
WebView#snapshot
SwingFXUtils#fromFXImage
I want to choose certain tabs of a browser via java code. For example , I want to access 3rd or the last tab of browser and oper some web page over there. Is there a way ?
It might be worth looking at how something like adobe brackets does this. It uses the developer mode in chrome (I think) which allows it to interact with tabs in chrome. However I don;t know if this is available in a non developer mode.
I don't think it's possible.
You can probably do that if you are having your own browser running in java.
I have a web page which is divided into several iFrames.
In each frame is a different solution, like JavaScript in one, flash in another, applet in another.
When a user interacts with the Applet, I am trying to provide a solution where if a certain event happens in the Applet, that the Applet will die and the same iFrame gets loaded with another solution (with an href like solution). I want to be able to load another Applet, or a raw HTML solution, or whatever.
I suspect I need to wrap these solutions in something else like JavaScript, but wondering what would this solution look like.
Thanks in advance.
See Applet.getAppletContext().showDocument(url, target).
Note that it is not guaranteed to be implemented in the JRE/browser combo. the applet is loaded in, let alone work. That is where the JavaScript comes in. ;)
It appears the start page is an html document rendered somehow. I know about jWebPane, but its dead and the only other active solution I can find is to embed firefox which is a huge dependency and eats up a ton of memory. Is there any lightweight solution for this?
JEditorPane is the built in Java webpage viewer. It's not a full blown browser but it should do the trick!
The nice part is that it will let you handle link clicks, for instance you could open a screen of you application when the user clicks a link.
CSS seems to be partially supported according to this StackOverflow question/answer