I am having the following problem. I have written a java snippet that reads an html file of known structure(see below). I split it in elements and get their text using the jericho parser. Then as soon as I print the text to ensure that the retrieval is correct I add each element into an ArrayList(obviously the retrieval is correct). As you can guess from the html structure if element i of ArrayList is Email then element i+1 is the value. I think its a scope problem but cant figure it out. Can you help? I am using the following code to grab the values:
private static void setVariables()
{
count=0;
for(String s:str)
{
if(s.contains("Email"))
{
email=getValue(email, count);
}
}
}
private static String getValue(String var, int count)
{
var=str.get(count+1);
count++;
return var;
}
private static void getElementsText(Source source)
{
List<Element> elementListTd = source.getAllElements(HTMLElementName.TD);
//Scroll through the list of elements "td" page
int i=0;
for (Element element : elementListTd) {
if (element.getAttributes() != null) {
String td = element.getAllElements().toString();
String tag = "td";
// System.out.println("TD: " + td);
// System.out.println(element.getContent());
String contentsAttributes = element.getTextExtractor().toString();
// System.out.println("line "+i+" "+contentsAttributes);
if(!contentsAttributes.isEmpty())
{
str.add(contentsAttributes);
}
}
}
str.add(" ");
setVariables();
}
public static void main(String[] args) throws FileNotFoundException, IOException
{
FileReader fr=new FileReader("32EPS 2012-ABSTRACT ~ 1333134955.html");
BufferedReader br=new BufferedReader(fr);
getTextFromFile(br);
Source source = new Source(html_txt);
getElementsText(source);
}
HTML:
<tr><td class='text11' nowrap>Email</td><td class='text11'>[email protected]<td></tr>
<tr><td class='text11' nowrap>Gender</td><td class='text11'>Mr<td></tr>