I need to open the first link of a youtube search in a webview

Asked

Viewed 48 times

0

The webview will not be visible, so the goal is to automatically open the first video of the search. I believe it is not too complicated in JS.

code:

public class FXMLDocumentController implements Initializable {

    @FXML
    private WebView tela;

    @FXML
    private Button botão;

    WebEngine webengine;

    @Override
    public void initialize(URL url, ResourceBundle rb) {

        webengine = tela.getEngine();

        webengine.load("https://www.youtube.com/results?search_query=exemplo");
    }    
  • This function returns the link: Document.getElementsByClassName('yt-simple-endpoint style-Scope ytd-video-Renderer')[0]. getattribute('href'). But for some reason it gives error when running inside Javafx. getElementById only takes if it is only 1 element.

  • From what I researched, the most practical would be to use a code in JS

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.