trying to get the conetnt of site when calling URL.
url=https://seekingalpha.com/symbol/AAPL/dividends/scorecard
in browser - it is working !
from java code i get:
Your current browser configuration
is not compatible with this site.
my code:
package com;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
public class Div4u {
public static String getURLToString(String strUrl) throws IOException {
String content = "";
URLConnection connection = new URL(strUrl).openConnection();
//connection.setRequestProperty("User-Agent", "Mozilla/5.0");
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 OPR/60.0.3255.170");
//connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
connection.connect();
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charset.forName("UTF-8")));
String inputLine;
while ((inputLine = br.readLine()) != null) {
content += inputLine;
System.out.println(inputLine);
}
br.close();
System.out.println("content:" + content);
return content;
}
// main method
public static void main(String[] args)
throws NumberFormatException,
IOException
{
try {
String urlContenet = getURLToString("https://seekingalpha.com/symbol/AAPL/dividends/scorecard");
} catch (Exception e) {
e.printStackTrace();
}
}
}