【发布时间】:2014-04-30 20:19:43
【问题描述】:
我正在做一个情绪分析项目。我正在使用 JAVA 从给定的产品 URL 中提取数据(产品评论),而用户通过浏览网站来选择产品。我需要从浏览器的地址栏中获取 URL 并将其传递给我的 JAVA 代码。如何提取 URL?如何链接这两个代码?我已经在我的 java 代码中使用 jsoup 库来从用户从 Eclipse 中的控制台指定的链接中提取评论。有什么方法可以让用户只选择产品并自动从地址栏中获取 URL?这是我用于提取评论的 JAVA 代码。 任何帮助,将不胜感激。
public class dataextraction {
public static void main(String[] args) {
Document doc;
try {
String link;
System.out.println("Enter the link of the product to be reviewed");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
link=in.readLine();
// need http protocol
doc = Jsoup.connect(link).get();
// get page title
String title = doc.title();
System.out.println("title : " + title);
Elements p= doc.select("p.line.bmargin10");
//get all links
String text = p.text();
System.out.println("text : " + text);
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter("E:/output.txt"));
writer.write(text);
}
catch (IOException e) {
System.err.println(e);
}
finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
System.err.println(e);
}
}
}
} catch (IOException e) {
e.printStackTrace();
System.out.println(e);
}
}
}
【问题讨论】:
-
你想用java提取浏览器的URL吗??
-
你会的。我只需要提取 URL 并将其传递给 JAVA 代码。
-
请发布代码以获取数据,以便人们可以帮助您
-
您的 java 代码是否在 web 服务器上的 applet、单独的进程中运行...?
-
给您带来的不便,我深表歉意。我编辑了我的问题并添加了必要的信息。