我正在尝试使用JSoup从股票代码中提取文章链接。
例如在此页面上:http://finance.yahoo.com/q/p?s=+AAPL+Press+Releases 有一堆新闻稿标题。当您按下每个标题时,您将获得一个链接。我想使用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()语句以获取链接。
答案 0 :(得分:0)
试试这段代码:
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/powerful-siri-capabilities-single-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-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-revolutionize-iphone-183000583.html