#javascript #jquery #javafx #youtube #webengine
#javascript #jquery #javafx #YouTube #веб-инженер
Вопрос:
Я хочу, чтобы моя программа автоматически нажимала больше, затем нажимала транслитерацию следующей страницы YouTube с помощью jquery в javafx
Цель, которую я хочу получить, расшифрована в исходном коде, я мало что знаю о jquery, если возможно, желаю, чтобы вы мне помогли
package templates;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import org.w3c.dom.Document;
/**
*
* @author Administrator
*/
public class FXMLDocumentController implements Initializable {
@FXML
private WebView browser;
@FXML
private Button btnScan;
@FXML
private TextArea txtAvailable;
////////////////////////////////////////////////////////////////////////
@FXML
void btnScan(ActionEvent event) {
final WebEngine engine = browser.getEngine();
engine.load("http://www.youtube.com/watch?v=8nECBJ1xRRA");
engine.documentProperty().addListener((ObservableValue<? extends Document> prop, Document oldDoc, Document newDoc) -> {
executejQuery(
engine,
"$("span.yt-uix-button-content").click(function(event){});"
);
});
System.out.println((String) webEngine.executeScript("document.documentElement.outerHTML"));
}
////////////////////////////////////////////////////////////////////////
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
public static final String DEFAULT_JQUERY_MIN_VERSION = "1.7.2";
public static final String JQUERY_LOCATION = "http://code.jquery.com/jquery-1.7.2.min.js";
/**
* Enables Firebug Lite for debugging a webEngine.
*
* @param engine the webEngine for which debugging is to be enabled.
*/
private static void enableFirebug(final WebEngine engine) {
engine.executeScript("if (!document.getElementById('FirebugLite')){E = document['createElement' 'NS'] amp;amp; document.documentElement.namespaceURI;E = E ? document['createElement' 'NS'](E, 'script') : document['createElement']('script');E['setAttribute']('id', 'FirebugLite');E['setAttribute']('src', 'https://getfirebug.com/' 'firebug-lite.js' '#startOpened');E['setAttribute']('FirebugLite', '4');(document['getElementsByTagName']('head')[0] || document['getElementsByTagName']('body')[0]).appendChild(E);E = new Image;E['setAttribute']('src', 'https://getfirebug.com/' '#startOpened');}");
}
/**
* Executes a script which may reference jQuery function on a document.
* Checks if the document loaded in a webEngine has a version of jQuery
* corresponding to the minimum required version loaded, and, if not, then
* loads jQuery into the document from the default JQUERY_LOCATION.
*
* @param engine the webView engine to be used.
* @Param jQueryLocation the location of the jQuery script to be executed.
* @param minVersion the minimum version of jQuery which needs to be
* included in the document.
* @param script provided javascript script string (which may include use of
* jQuery functions on the document).
* @return the result of the script execution.
*/
private static Object executejQuery(final WebEngine engine, String minVersion, String jQueryLocation, String script) {
return engine.executeScript(
"(function(window, document, version, callback) { "
"var j, d;"
"var loaded = false;"
"if (!(j = window.jQuery) || version > j.fn.jquery || callback(j, loaded)) {"
" var script = document.createElement("script");"
" script.type = "text/javascript";"
" script.src = "" jQueryLocation "";"
" script.onload = script.onreadystatechange = function() {"
" if (!loaded amp;amp; (!(d = this.readyState) || d == "loaded" || d == "complete")) {"
" callback((j = window.jQuery).noConflict(1), loaded = true);"
" j(script).remove();"
" }"
" };"
" document.documentElement.childNodes[0].appendChild(script) "
"} "
"})(window, document, "" minVersion "", function($, jquery_loaded) {" script "});"
);
}
private static Object executejQuery(final WebEngine engine, String minVersion, String script) {
return executejQuery(engine, DEFAULT_JQUERY_MIN_VERSION, JQUERY_LOCATION, script);
}
private Object executejQuery(final WebEngine engine, String script) {
return executejQuery(engine, DEFAULT_JQUERY_MIN_VERSION, script);
}
}
Комментарии:
1. Не могли бы вы объяснить, что вы подразумеваете под «целью, которую я хочу получить транскрибированной в исходном коде»? Мне трудно понять, что именно вы ищете?