I would like to type some text in textfield, and then select a, if a is not available, then select b, finally submit the information. I just write these code and get no idea what can I do next.
URL page_1 = new URL("https://google.com.hk");
HttpURLConnection urlconnection = (HttpURLConnection) page_1.openConnection();
DataOutputStream data_out = new DataOutputStream(urlconnection.getOutputStream());
DataInputStream data_in = new DataInputStream(urlconnection.getInputStream());
urlconnection.setDoInput(true);
urlconnection.setDoOutput(true);
System.out.println(data_out);
System.out.println(data_in);
System.out.println(urlconnection);
Lukas Knuth
25.8k16 gold badges88 silver badges114 bronze badges
-
I just don't understand, get us a jsFiddleSudharsun– Sudharsun2013年10月05日 11:06:09 +00:00Commented Oct 5, 2013 at 11:06
1 Answer 1
Java won't load the page and execute the JS code it contains like a browser would do. All it will do is load the data sent by the server in the response.
If you want a programmable browser in Java, then look at Selenium or HtmlUnit.
answered Oct 5, 2013 at 11:10
JB Nizet
694k94 gold badges1.3k silver badges1.3k bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
user2760979
How can I send data to server?? Let say I would like to use java to search stackoverflow at Google. And then show the first website's name at java. How can I do that?
JB Nizet
Send data with what? Plain Java HttpUrlConnection? HtmlUnit? Selenium? Have you read the answer and read the documentation of HtmlUnit and Selenium?
default