how to parse a table without an Id tag. I'm trying to parse a table with source code line 2290 to 3153 http://pastebin.com/DjGHED5t
It isn't obvious to me as to how to do it. what I have now is
import java.util.*;
import java.io.*;
import java.awt.*;
import javax.swing.*;
import org.jsoup.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class test{
public static void main (String []args){
String Ticker = "KO";
URL url = new URL("http://toolbox.investools.com/graphs/fundamentalAnalysis.iedu?report=BS&symbol="+(Ticker));
Document doc = Jsoup.parse(url, 3000);
Elements table = doc.select(table);
Iterator<Element> ite = table.select(table[width="100%"] [bgcolor="#CCCCCC"] [cellpadding="0"] [cellspacing="2"]);
String[][] balanceSheetInfo = new String [46][11];
while (ite.hasNext()){
for (int row = 0, row_size = balanceSheetInfo[row].length; row < row_size; row++){
for (int col = 0, col_size = balanceSheetInfo.length; col < col_size; col++){
if(ite.hasNext()){
balanceSheetInfo[col][row] = input.next();
System.out.printf("%s",balanceSheetInfo[col][row]); }
}
}
}
}
}
But i am getting symbol not found errors. I am not strong with Jsoup and scraping given this is the first project I have used it in. If someone could guide me it would be greatly appreciated.
Read your code:
Elements table = doc.select(table);
You're using the table variable (in doc.select(table)
) before it's even declared. The Element.select()
method takes a String as argument. You need
Elements table = doc.select("table");
with double quotes, which will select all the table elements.
The next line has the same problem:
table.select(table[width="100%"] [bgcolor="#CCCCCC"] [cellpadding="0"] [cellspacing="2"]);
should be
table.select("table[width=\"100%\"] [bgcolor=\"#CCCCCC\"] [cellpadding=\"0\"] [cellspacing=\"2\"]");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.