Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class FinanceParser extends PageParser
- {
- private int addNext;
- private double price;
- private String name;
- private String symb;
- private ArrayList<String> others;
- public FinanceParser(String site, String page)
- {
- super(site, page);
- others = new ArrayList<String>();
- }
- public void saveData(String line)
- {
- if(others == null)
- others = new ArrayList<String>();
- super.saveData(line);
- int find;
- int findEnd;
- if(addNext != 0)
- {
- find = line.indexOf(">");
- findEnd = line.indexOf("<", find);
- price = Double.parseDouble(line.substring(find + 1, findEnd));
- addNext = 0;
- }
- if(line.equals("<span class=\"pr\">"))
- addNext = 1;
- else if(line.length() > 14 && line.substring(0, 7).equals("<title>"))
- {
- find = line.indexOf(":", 7);
- name = line.substring(7, find);
- find = line.indexOf(":", find + 1);
- findEnd = line.indexOf(" quotes", find);
- symb = line.substring(find + 1, findEnd);
- }
- else if(symb != null && line.startsWith("title = \"" + symb + ": {LAST} {CHANGE} ({CHANGE_PCT}%)"))
- {
- find = line.indexOf("_aQ(", 40);
- while(find != -1)
- {
- find = line.indexOf(":", find);
- findEnd = line.indexOf("\"", find);
- if(find != -1 && findEnd != -1)
- {
- String s = line.substring(find + 1, findEnd);
- System.out.println(s);
- if(s != null && s != "" && !s.equals(symb))
- others.add(s);
- //System.out.println(others);
- }
- //find = line.indexOf("_aQ(", findEnd);
- find = line.indexOf("_aQ(", find + 1);
- }
- }
- }
- public double getPrice()
- {
- return price;
- }
- public String getName()
- {
- return name;
- }
- public String getSymbol()
- {
- return symb;
- }
- public ArrayList<String> getOthers()
- {
- System.out.println(others);
- return others;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement