我试图得到股票的股票代码,这是3-4个字母的代码,可以唯一地识别股票。下面是我试图使用的代码。
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class Alpha {
public static void main(String[] args) {
Document doc;
try {
// need http protocol
doc = Jsoup.connect("http://www.bloomberg.com/markets/stocks/movers/ftse-100/").get();
// get page title
String title = doc.title();
System.out.println("title : " + title);
// get all links
Elements links = doc.select("a[href=");
for (Element link : links) {
// get the value from href attribute
System.out.println("\nlink : " + link.attr("href"));
System.out.println("text : " + link.text());
}
} catch (IOException e) {
e.printStackTrace();
}然而,我不想得到所有的链接,我想从网页上获得具体的链接。例如,我想获得的数据片段之一的HTML代码是:
<tr class="odd">
<td class="first name">
<a href="/quote/AGK:LN">Aggreko PLC</a>
</td>
<td class="value">1,594.00</td>
<td class="change up">+52.00</td> <td class="delta up">+3.37%</td> <td class="value">1,561,246</td>
<td class="datetime">11:35:00</td>
</tr>在我想要在屏幕上输出的数据中,使用标记//AGK:。如何使程序只选择HTML的那一部分?
干杯
发布于 2014-11-14 21:16:33
在cssquery中,您只需将类似于"a[href='blablbla']"的值
所以试试这个
Elements links = doc.select("a[href='/quote/AGK:LN']");https://stackoverflow.com/questions/26938871
复制相似问题