Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Relates :
|
ADDITIONAL SYSTEM INFORMATION : WINDOWS 10 - JRE8u321 A DESCRIPTION OF THE PROBLEM : HCAPTCHA considere the Java WEBBrowser as a robot and loops on the captcha. The captcha works well, but the page I want to reach never appears ! STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Execute script EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - RECAPTCHA WORKS FINE, BUT HCAPTCHA CONSIDERE JAVA WEBBROWSER AS ROBOT ! LOOP ON THE HCAPTCHA. ---------- BEGIN SOURCE ---------- package _TEST; import java.awt.BorderLayout; import java.io.File; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import javax.swing.JFrame; import javax.swing.JPanel; import com.sun.javafx.application.PlatformImpl; import javafx.application.Platform; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.ObservableList; import javafx.concurrent.Worker.State; import javafx.embed.swing.JFXPanel; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.web.WebEngine; import javafx.scene.web.WebView; import javafx.stage.Stage; class CL_SwingFXWebView extends JPanel { private static JFrame f = null; public static void main(String[] args) { f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new CL_SwingFXWebView(); f.getContentPane().add(p); f.setSize(800, 600); f.setVisible(true); ((CL_SwingFXWebView) p).load("https://www.pagesjaunes.fr/"); } private static final long serialVersionUID = 8990771757800321056L; private Stage stage = null; private WebView browser = null; private JFXPanel jfxPanel = null; private WebEngine webEngine = null; public CL_SwingFXWebView() { jfxPanel = new JFXPanel(); PlatformImpl.startup(new Runnable() { public void run() { stage = new Stage(); Group root = new Group(); Scene scene = new Scene(root); stage.setScene(scene); browser = new WebView(); webEngine = browser.getEngine(); webEngine.setUserDataDirectory(new File(".")); //webEngine.setUserAgent("use required / intended UA string"); //NOT WORKING ! //webEngine.setUserAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5"); webEngine.setJavaScriptEnabled(true); TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() { public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws java.security.cert.CertificateException {} public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException {} public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } }}; SSLContext sc = null; try { sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } HostnameVerifier allHostsValid = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } }; HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() { public void changed(ObservableValue<? extends State> ov, State oldState, State newState) { if (newState == State.RUNNING) { } if (newState == State.SUCCEEDED) { f.setTitle(webEngine.getLocation()); } } }); webEngine.getLoadWorker().progressProperty().addListener(new ChangeListener<Number>() { public void changed(ObservableValue<? extends Number> ov, Number oldNumber, Number newNumber) { } }); ObservableList<Node> children = root.getChildren(); children.add(browser); jfxPanel.setScene(scene); } }); setLayout(new BorderLayout()); add(jfxPanel, BorderLayout.CENTER); } public void setPrefDimension(double _dWidth, double _dHeight) { if (browser != null) { browser.setPrefWidth(_dWidth);browser.setPrefHeight(_dHeight); } } public WebEngine getEngine() { return webEngine; } public void load(final String _sURL) { Platform.runLater(new Runnable() { public void run() { webEngine.load(_sURL); } }); } public void reloadPage() { Platform.runLater(new Runnable() { public void run() { webEngine.reload(); } }); } public void navigateBack() { Platform.runLater(new Runnable() { public void run() { webEngine.executeScript("history.back()"); } }); } public void navigateForward() { Platform.runLater(new Runnable() { public void run() { webEngine.executeScript("history.forward()"); } }); } public void stopLoading() { Platform.runLater(new Runnable() { public void run() { webEngine.executeScript("window.stop()"); } }); } public String getHTMLContent() { return webEngine.executeScript("document.documentElement.innerHTML").toString(); } public String getURL() { return webEngine.getLocation(); } } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : RECAPTCHA WORKS FINE, BUT HCAPTCHA BUGS ! FREQUENCY : always
|