提取文章仅使用jsoup链接



我正在尝试使用jsoup从股票符号中提取文章的链接。

例如,在此页面上:http://finance.yahoo.com/q/p?s= aapl press relealeases有很多新闻稿标题。按下每个标题时,将为您提供一个链接。我想使用jsoup提取和存储每个新闻稿的链接。

到目前为止,这就是我到目前为止所拥有的:

   Document doc = Jsoup
            .connect("http://finance.yahoo.com/q/p?s=AAPL+Press+Releases").get();

并获得我正在使用的链接

Elements url = jSoupDoc.select("p").select("a");
System.out.println(url.text());

我要获得的输出不仅仅是链接,我会收到其他一些信息。请帮助我调整.select()语句以仅获取链接。

尝试以下代码:

    Document document = Jsoup.connect("http://finance.yahoo.com/q/p?s=+AAPL+Press+Releases")
                         .get();
    Element div = document.select("div.mod.yfi_quote_headline.withsky").first();
    Elements aHref = div.select("a[href]");
    for(Element element : aHref)
        System.out.println(element.attr("abs:href"));

输出:

http://finance.yahoo.com/news/hagens-berman-payday-millions-e-161500428.html http://finance.yahoo.com/news/swift-playgrounds-app-makes-learning-185500537.html http://finance.yahoo.com/news/apple-previews-ios-10-biggest-185500113.html http://finance.yahoo.com/news/poperuful-siri-capabilities-single-sign-sign-185500577.html http://finance.yahoo.com/news/apple-previews-major-macos-sierra-185500097.html http://finance.yahoo.com/news/apple-previews-watchos-3-faster-185500388.html http://finance.yahoo.com/news/apple-union-square-highlights-design-173000006.html http://finance.yahoo.com/news/apple-opens-development-office-hyderabad-043000495.html http://finance.yahoo.com/news/apple-anple-announces-ios-app-design-043000238.html http://finance.yahoo.com/news/apple-celebrates-chinese-music-garageband-230000088.html http://finance.yahoo.com/news/apple-sap-partner-revolution-partner-revolution-iphone-183000583.html

最新更新