如何使用javas内置的javascript引擎在网页上运行脚本?
我想在我的播放器中显示歌曲的歌词。我曾经使用lyricsplugin.com,因为它有很多英语和俄语歌词,但最近他们将网站从静态页面更改为ajax 驱动的页面。搜索歌词遵循以下模式:
http://www.lyricsplugin .com/winamp03/plugin/?artist=Linkin%20Park&title=Numb
它显示一个空页面,并且在正文 onload 中:
javascript:getContent('Linkin%20Park', 'Numb', '1281528101', '5e22e4e3979026a9af59ee16ff82fe1f')
而 getContent
看起来像这样:
function getContent(artist, title, time, check) {
xmlHttp = GetXmlHttpObject();
if(xmlHttp == null)
{
return;
}
var url = "content.php?artist=" + artist + "&title=" + title + "&time=" + time + "&check=" + check;
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
stateChanged( )
然后将响应放入页面中相应的div中。
所以我想我可以下载该页面并构建一个 DOM 树,因为它是 XHTML。如何使用内置的 rhino 引擎执行 JavaScript 并最好覆盖 stateChanged()
函数?我似乎无法直接调用 content.php
脚本。
除了lyrics.wikia.com 之外,没有其他资源有那么多歌词(尤其是俄语),但它们不允许屏幕抓取。
更新:
歌词插件似乎正在使用justsomelyrics.com并且有一个谷歌自定义搜索框。我怎样才能从java访问它?
I want to show lyrics for songs in my player. I used to use lyricsplugin.com because it had a lot of English and Russian lyrics, but recently they've changed their web-site from being a static page to an ajax-powered page. Searching lyrics follows this pattern:
http://www.lyricsplugin.com/winamp03/plugin/?artist=Linkin%20Park&title=Numb
It shows an empty page and this in body onload:
javascript:getContent('Linkin%20Park', 'Numb', '1281528101', '5e22e4e3979026a9af59ee16ff82fe1f')
while getContent
looks like this:
function getContent(artist, title, time, check) {
xmlHttp = GetXmlHttpObject();
if(xmlHttp == null)
{
return;
}
var url = "content.php?artist=" + artist + "&title=" + title + "&time=" + time + "&check=" + check;
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
stateChanged()
then puts response into corresponding div in the page.
So I guess I can download the page and build a DOM tree since it is XHTML. How do I use the built in rhino engine to execute the javascript and preferably override the stateChanged()
function? I don't seem to be able to call that content.php
script directly.
No other resource has that many lyrics (especially Russian) except for lyrics.wikia.com, but they don't allow screen scraping.
UPDATE:
lyricsplugin seems to be using justsomelyrics.com and there is a google custom search box. How can I access it from java?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的是 SWT 浏览器组件。只需调用
setURL(String)
即可显示网页。这为您提供了一个功能齐全的浏览器,包含 Javascript 和所有内容。The simplest is the SWT Browser component. Simply call
setURL(String)
and it will display the web page. This gives you a full fledged browser with Javascript and everything.