【问题标题】:jsoup get data from websitejsoup 从网站获取数据
【发布时间】:2017-09-10 06:23:08
【问题描述】:

我正在使用 Java jsoup 从http://www.aastocks.com/en/ltp/rtquote.aspx?symbol=00055&process=y 获取“最后”价格

我的代码:

String price = null;
Document document = Jsoup.connect("http://www.aastocks.com/tc/ltp/rtquote.aspx?symbol=00055").ignoreHttpErrors(true).timeout(5*1000).get();  // s
Elements answerers = document.select(".C.font28.bold ");
price = answerer.text();
        }

 System.out.println(price);

但它会返回:

run:

BUILD SUCCESSFUL (total time: 0 seconds)

请帮忙

【问题讨论】:

  • 很可能你的元素选择器是错误的。我们应该怎么知道?您是否检查过具有此类/名称/...的元素存在?
  • 那么我应该使用什么选择?
  • 我正在做的是把所有股票的“最后”价格降到我的电脑上
  • 价格 = answerer.text() ?或价格 = answerers.text(); ?.我猜后面一个是正确的

标签: java web-scraping jsoup


【解决方案1】:

获取例如Firefox 的 CSS 选择器:

  • 右键单击要获取其选择器的元素。
  • 选择“检查”或“使用 Firebug 进行检查”。
  • 然后右键单击选定的源并选择“复制 CSS 路径”。

你会得到这个 CSS 路径:

html body div#AAMainMaster div.floatL div.frame_w.floatL div div.c_w div.div-container div.RContentBox.floatL form#aspnetForm div.div-container div.floatL div.div-container.bmp-s1 div#rtQuoteRightContent.floatL div.div-container table.tb-s4 tbody tr td.DR.bold

希望对你有帮助

问候

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多