Edit browser's text field using java - java

Is it possible to edit browser's text field using java? Currently I'm using Jsoup to gather some information about websites so I'm looking for some more options.Could JSoup to this? Thank you!

I don't see how JSoup would help here. JSoup is just a way to parse html. You could use it to write out some html that has a text field in it with an input tag that has a value attribute on it. Then when you render the file in a browser, the page would have that value. But since you haven't given us very much information, I'm not sure if this is exactly what you want to do or completely different from what you want to do.
This is probably the last thing you'd want to do (not the first), but you could set the values of a text field using Java's Robot class.

Related

Getting a specific value from a webpage from scraped HTML

Curerntly using Java to scrape the HTML code from this page http://counter.onlineclock.net/
I want to get the value from the counter, but this is unique for each version of the webpage, that is, if its open in different browsers or for different people it will be a different value.
Because of this, when I scrape the HTML, the value that I am looking for is just blank. I am wondering if there is any way at all for me to get the current value I am looking for.
For example, if I have the counter at 4 I would like to be able to get that value. It does not have to be in java, any language or any way.
JSoup is a great library for scraping data out of a web page. There are a lot of good examples of its usage on the web

parsing html page in java without using external library

I know its an old question and have been asked many a times. Note :I cannot use external libraries.
Given a function with label as argument, my function should return list of all the tags that contain that label.
I thought of saving my html as tree and then I can find the label and return list of all the tags. But I am not able to code it in java. How to completely parse and store html as tree structure and search on it?
Please help.
Thanks
Ravi

How to get Javascript var value in Java (wicket 6)

I have a fairly simple question, but I'm unable to find a working answer.
I'm using javascript in my HTML file for a page that is taking input from the page and giving me back a string of a jSON object. All that I want to do is take this string and put it in a Java string.
I can do things like
target.appendJavaScript("s=getString();");
target.appendJavaScript("alert(s);")
which give me the desired information in the alert. But how do I get s into a Java string?
I have tried the following
StringValue temp = RequestCycle.get().getRequest().getQueryParameters().getParameterValue("s");
info(temp.toString());
And other variations like getRequestParameters(), but I get nulls on temp.
These actions are inside an AjaxFallbackButton's onSubmit.
Any advice on how to get a javascript var in Java?
Although I would still like to know more about sharing variables between Java and Javascript in HTML, my case was solved thanks to Wicket.
The value that I was retrieving with s=getString() was already accessible in a HiddenField, and so I simply needed to get it a wicket:id in the HTML and add it with a property model in the Java. Hopefully this might help someone else in the future.

Does JSoup achieve this?

I want to collect domain names (crawling). I have wrote a simple Java application that reads HTML page and save the code in text file. Now, I want to parse this text in order to collect all domain names without douplicates. But I need the domain names without "http://www.", just domainname.topleveldmian or the possibilities of dmianname.subdomain.topleveldomain or whatever number of subdomains (then, the collected links need to be extracted the same way and collect the links inside them till I reach certain number of links, say 100).
I have asked about this in previous posts https://stackoverflow.com/questions/11113568/simple-efficient-java-web-crawler-to-extract-hostnames , and searched. JSoup seems good solution but I have not worked with JSoup before, so before going deeply on it. I just want to ask: Does it achieve what I want to do ?? Any other suggestions for achieving my simple crawling in a simple way are welcome.
jsoup is a Java library for working with real-world HTML. It provides
a very convenient API for extracting and manipulating data, using the
best of DOM, CSS, and jquery-like methods
So yes, you can connect to a website extract its html and parse it with jsoup.
The logic of extracting the top level domain is "your part" you will need to write the code logic yourself.
Take a look at the docs for more options...
Use selector-syntax to find elements
Use DOM methods to navigate a document

How can I take links from a user and display them in my page properly?

I am developing a Java project in which I will take the text from a user in a textArea and generate an HTML page with that text.
I want to allow the user to add links in the generated HTML Page. As I am taking the page contents from the user, I also need to take the link name and the URL from the user.
How can I provide this functionality?
This is a bit vague ...
You don't say if you also somehow know where in the text the links need to be generated. If you don't, your problem is not solvable.
If you do, then I guess you just need to add some logic that tests if the current location in the output stream somehow corresponds to one of the locations where there should be a link, and generate the link.
The syntax for a HTML link can be found wherever, and I would assume you know it already, but just to be complete it looks like this:
link to example.com
Replace the part inside the quotes with the reference, and the text between > and < with the link name.
You'll need a database to store the links. Unless you want to show them only once.
String links = request.getParameter("textArea_name");
// then save it on your prefered database
To show it you can then load it from the database and just output them.

Categories