I am trying to get information such as the item title in the following grocery store flyer: http://www.yourindependentgrocer.ca/en_CA/[email protected]@896.html
I would like to System.out.println() all of the item names in Eclipse IDE. I am not sure how to get this information because the HTML from the above link does not seem to contain any items. Let alone when switching pages in the flyer the URL does not change...
To reiterate what I wish to accomplish here is an example that I did for another grocery store: http://www.metro.ca/flyer/index.en.html
However this one was easy because I didn't have to worry about pagination. All of the information came with the above URL's HTML. The following is my code to accomplish it:
I would like to accomplish this (outputting the items in Eclipse) for grocery store flyers that deal with pagination so I am trying to do it for this grocery store: http://www.yourindependentgrocer.ca/en_CA/[email protected]@896.html
I do not wish to use any third party webscraping application. I would like to know how to do it in java.
I would like to System.out.println() all of the item names in Eclipse IDE. I am not sure how to get this information because the HTML from the above link does not seem to contain any items. Let alone when switching pages in the flyer the URL does not change...
To reiterate what I wish to accomplish here is an example that I did for another grocery store: http://www.metro.ca/flyer/index.en.html
However this one was easy because I didn't have to worry about pagination. All of the information came with the above URL's HTML. The following is my code to accomplish it:
Code:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import org.apache.commons.lang3.StringEscapeUtils;
public class TestGroceryStore
{
public static void main(String[] args) throws Exception
{
URL flyerURL = new URL("http://www.metro.ca/flyer/index.en.html");
URLConnection connection = flyerURL.openConnection();
BufferedReader brFlyer = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder sbFlyer = new StringBuilder();
String flyerLine = null;
while((flyerLine = brFlyer.readLine()) != null)
sbFlyer.append(flyerLine + "\n");
String flyerHTML = sbFlyer.toString();
System.out.println(flyerHTML);
// GETTING ITEM NAME
while(flyerHTML.contains("\"shortDescription\":"))
{
String shortDescription = "";
String shortDescriptionTag = "\"shortDescription\":";
flyerHTML = flyerHTML.substring(flyerHTML.indexOf(shortDescriptionTag)+shortDescriptionTag.length());
if(flyerHTML.startsWith("null"))
shortDescription = "null";
else
shortDescription = StringEscapeUtils.unescapeHtml4(flyerHTML.substring(1, flyerHTML.indexOf(",\"longDescription\":")-1));
System.out.println("SHORT DESCRIPTION = " + shortDescription);
System.out.println("");
}
}
}
I would like to accomplish this (outputting the items in Eclipse) for grocery store flyers that deal with pagination so I am trying to do it for this grocery store: http://www.yourindependentgrocer.ca/en_CA/[email protected]@896.html
I do not wish to use any third party webscraping application. I would like to know how to do it in java.





























