如何在java中运行JavaScript方法?(我需要创建程序下载大约10k轨道)

USE*_*ER_ 5 javascript java download

在几天之内,"Wirtualna Polska SA"关闭了"mp3.wp.pl"服务,所以我决定从那里下载一些音乐并保存在我的硬盘上.它大约150k(我不需要所有btw.)的文件所以这样做我自己这样做会浪费时间.我创建了一个程序,下载所有特定类型的ID并将其保存到*.txt文件夹中.要从网站下载音乐,我需要使用他们网站上的javascript方法download_utId('id'),其中id是*.txt文件中的一个int

  1. 我可以在java中运行此方法(download_utId)吗?
  2. 您如何优化我的代码?
  3. 还有其他任何建议吗?

4.(编辑.)如何用自己的名字保存文件?当你想下载"http://mp3.wp.pl/i/sciagnij?id=666&jakosc=hifi&streaming=0"这个文件的默认名称是"Dub_Brother-Dance_Mission"

import java.io.*; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; public class Test { public static int numberOfPages = 1; public ArrayList<String> downloadPage(String page, String findAString, String endString){ ArrayList<String> listOfIDs = new ArrayList<String>(); URL url; InputStream is = null; DataInputStream dis; String line; try { url = new URL(page); is = url.openStream(); // throws an IOException dis = new DataInputStream(new BufferedInputStream(is)); while ((line = dis.readLine()) != null) { if(line.contains("Liczba znalezionych utworów:")){ numberOfPages = numberOfPages(new Integer(line.substring(line.indexOf("<b>") + 3, line.lastIndexOf("</b>. Po")))); } if(line.contains(findAString)){ listOfIDs.add((line.substring(line.indexOf(findAString)+15, line.lastIndexOf(endString)))); } } } catch (MalformedURLException mue) { mue.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { try { is.close(); } catch (IOException ioe) { // nothing to see here } } return listOfIDs; } public int numberOfPages(int numberOfSongs){ return numberOfSongs - numberOfSongs/10*10 >= 5 ? numberOfSongs/10+1 : numberOfSongs/10; } public void addToFile(){ ArrayList<String> hehe = new ArrayList<String>(); for(int i = 0; i < numberOfPages; i++){ String link = "http://mp3.wp.pl/p/strefa/utwory/E9,nazwa," + i + "0,+0,+0,+0.html"; hehe.addAll(downloadPage(link, "download_utId('", "'")); System.out.print(link); } FileWriter writer = null; try { writer = new FileWriter("c:/output.txt"); for(String str: hehe) { writer.write(str + " "); } writer.close(); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args){ Test t = new Test(); t.addToFile(); } }
Run Code Online (Sandbox Code Playgroud)

d.r*_*aev 1

Rhino Utilities有一个不错的工具,不确定是否值得安装,但它很容易使用。