我想在"http://www.aastocks.com/en/ltp/rtquote.aspx?symbol=01319“中获得”收益率“的值
我已经尝试过"Jsoup“,我的代码如下:
public static void main(String[] args) throws IOException {
String url = "http://www.aastocks.com/en/ltp/rtquote.aspx?symbol=01319";
Document document = Jsoup.connect(url).get();
Elements answerers = document.select(".c3 .floatR ");
for (Element answerer : answerers) {
System.out.println("Answerer: " + answerer.data());
}
// TODO code application logic here
}但它是空的。我该怎么做?
发布于 2016-06-07 09:20:08
你的密码没问题。我亲自测试过。问题在于你使用的URL。如果我在浏览器中打开url,则值字段(例如收益率)为空。使用浏览器开发工具(网络选项卡),您应该获得如下URL:
http://www.aastocks.com/en/ltp/RTQuoteContent.aspx?symbol=01319&process=y
使用这个URL会给出想要的结果。
发布于 2016-06-07 09:10:49
最简单的解决方案是创建一个指向您想要的网页/链接的URL实例,使用流获取内容-
例如-
public static void main(String[] args) throws IOException
{
URL url = new URL("http://www.aastocks.com/en/ltp/rtquote.aspx?symbol=01319");
// Get the input stream through URL Connection
URLConnection con = url.openConnection();
InputStream is =con.getInputStream();
// Once you have the Input Stream, it's just plain old Java IO stuff.
// For this case, since you are interested in getting plain-text web page
// I'll use a reader and output the text content to System.out.
// For binary content, it's better to directly read the bytes from stream and write
// to the target file.
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = null;
// read each line and write to System.out
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}发布于 2016-06-07 09:13:03
我认为珍汤在这方面是至关重要的。我不会怀疑一个有效的HTML文档(或其他什么)。
https://stackoverflow.com/questions/37674919
复制相似问题