簡體   English   中英

HTMLUNIT Java Javascript Ajax

[英]HTMLUNIT java javascript ajax

我正在嘗試解析一個視頻資源Cinemaonline.kg,以獲取指向視頻文件的鏈接。 首先,我嘗試將打開的頁面保存在記事本中。 我看着它,發現:

[a id="onlineplayer" onmouseover="jQuery('a#onlineplayer').fancybox({'width' : '8', 'height' : 430, 'autoScale' : true, 'transitionIn' : 'none', 'transitionOut' : 'none', 'type' : 'iframe' , 'closeClick' : 'false' , 'hideOnOverlayClick':false, 'hideOnContentClick':false});" onclick="window.ui.hitMovie(74);window.ui.setFileDownloaded(74);" class="minibutton" href="http://cinemaonline.kg/pl.php?player=ftp&uid=1953&movieid=74&fileid=74&v=6b576ed87c32f85f9252e80591ca1228">[span]Смотреть[/span][/a] 'hideOnContentClick':false});" onclick="window.ui.hitMovie(74);window.ui.setFileDownloaded(74);" class="minibutton" href="http://cinemaonline.kg/pl.php?player=ftp&uid=1953&movieid=74&fileid=74&v=6b576ed87c32f85f9252e80591ca1228">[span]Смотреть[/span][/a]

<>-此字符已與此字符-[]更改,因為未顯示。

所以我試圖用jsoup來抓它。 但是它返回了我nullpointer異常。 我查看了返回的頁面字符串,沒有標簽[id =“ onlineplayer” ...]。 我認為,也許頁面始終是由一個腳本生成的:

[a id=\\"onlineplayer\\" onmouseover=\\"jQuery(\\'a#onlineplayer\\').fancybox({\\'width\\' : \\'8\\', \\'height\\' : 430, \\'autoScale\\' : true, \\'transitionIn\\' : \\'none\\', \\'transitionOut\\' : \\'none\\', \\'type\\' : \\'iframe\\' , \\'closeClick\\' : \\'false\\' , \\'hideOnOverlayClick\\':false, \\'hideOnContentClick\\':false});\\" onclick=\\"window.ui.hitMovie(${movie.movie_id});window.ui.setFileDownloaded(${file.file_id});\\" class=\\"minibutton\\" href=\\"${file.links.license|escape}\\"][span]Смотреть[/span][/a]

比我試圖用HtmlUnit解析它:

String url = "http://cinemaonline.kg/#/movie/id/74";
WebClient webClient = new WebClient();
webClient.setJavaScriptEnabled(true);
HtmlPage page = null;
webClient.setThrowExceptionOnFailingStatusCode(false);
webClient.setThrowExceptionOnScriptError(false);
try {
    page = webClient.getPage(url);
} catch (FailingHttpStatusCodeException e1) {
    e1.printStackTrace();
} catch (MalformedURLException e1) {
    e1.printStackTrace();
} catch (IOException e1) {
    e1.printStackTrace();
}
webClient.waitForBackgroundJavaScript(10000);
webClient.closeAllWindows();
System.out.println(page.asXml());

但是它給了我與jsoup返回的相同的文本。 我知道頁面使用javascript和ajax(?),但是我真的不知道它是如何工作的。 如何返回生成的文本? 請幫忙

檢查此問題以獲取圖像鏈接Jsoup:如何獲取圖像的絕對URL?

同樣,您可以獲取視頻元素,並在其上使用yourvideoelement.attr(“ href”)以獲取返回的鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM