Web scraping: Difference between revisions

m (→‎{{header|Phix}}: skip site notice)
Line 1,032:
 
=={{header|Java}}==
 
<syntaxhighlight lang="java">import java.io.BufferedReader;
}</syntaxhighlight>
 
<syntaxhighlight lang="java">import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URLConnectionHttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
 
 
public final class WebTime{
public static void main(String[] argsaArgs) {
try {
URL address = new URL(
URI uri = new URI("https://www.rosettacode.org/wiki/Talk:Web_scraping").parseServerAuthority();
"http://tycho.usno.navy.mil/cgi-bin/timer.pl");
URLConnection conn =URL address = uri.openConnectiontoURL();
HttpURLConnection connection = (HttpURLConnection) address.openConnection();
BufferedReader in = new BufferedReader(
BufferedReader reader = new BufferedReader( new InputStreamReader(connconnection.getInputStream()) );
String line;
final int responseCode = connection.getResponseCode();
while(!(line = in.readLine()).contains("UTC"));
System.out.println(line.substring(4)"Response code: " + responseCode);
}catch(IOException e){
String line;
System.err.println("error connecting to server.");
while ( ! ( line = inreader.readLine() ).contains("UTC") ); {
e.printStackTrace();
/* Empty block */
}
}
}</syntaxhighlight>
final int index = line.indexOf("UTC");
System.out.println(line.substring(index - 16, index + 4));
reader.close();
connection.disconnect();
} catch (IOException eioe) {
System.err.println("errorError connecting to server.: " + ioe.getCause());
} catch (URISyntaxException use) {
System.err.println("Unable to connect to URI: " + use.getCause());
}
}
}
}
</syntaxhighlight>
{{ out }}
<pre>
Response code: 200
25 August 2022 (UTC)
</pre>
 
=={{header|JavaScript}}==
881

edits