Read a web page
//package org.snancekivell.one_day_watcher;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.LinkedList;
public class site_utils {
public static final String ADDRESS_1_DAY = "http://www.1-day.co.nz/";
public static LinkedList<String> getpage(){
LinkedList<String> page = new LinkedList<String>();
try{
URL url = new URL(ADDRESS_1_DAY);
InputStream is =url.openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line;
while ((line=reader.readLine())!=null){
page.add(line);
}
}
catch(Exception e){
e.printStackTrace();
System.exit(1);
}
return page;
}
public static LinkedList<String> get_products(LinkedList<String> page) {
LinkedList<String> products= new LinkedList<String>();
for (int i=0; i< page.size();i++){
if (page.get(i).contains("<div class=\"productTitle\">"))
{
i+=2;
String head1= page.get(i).trim().replace("</h1>", "");
i+=2;
String head2 = page.get(i).trim().replace("</h2>", "");
i+=16;
String price = page.get(i).replace("<li class=\"amount\">", "").replace("</li>", "").trim();
products.add(head1+" : "+head2+" : "+price);
}
}
return products;
}
}
Related examples in the same category