Hello everyone, so I am pretty young and just getting into processing 2 years ago. I am doing this competition where I am planning to do some web scraping/parsing through Harvey Norman’s website. The project needs to be about PCs so I’m going to parse monitors. I have looked at Danny Shiffman’s video but still a bit confused trying to get it to work. This is bascially Daniel’s work with my poor attempt at what to do.
Thanks,
Water
String runningtime;
PImage poster;
void setup() {
size(300, 350);
loadData();
}
void draw() {
// Display all the stuff I want to display
background(255);
//image(poster, 10, 10, 164, 250);
fill(0);
text("Shaun the Sheep", 10, 300);
text(runningtime, 10, 320);
}
void loadData() {
String url = "https://www.harveynorman.com.au/acer-et322qr-31-5-curved-flat-panel-monitor.html";
// Get the raw HTML source into an array of strings (each line is one element in the array).
// The next step is to turn array into one long string with join().
String[] lines = loadStrings(url);
String html = join(lines, "");
String start = "\"final_price\":";
String end = ",\"hide_price\":";
runningtime = giveMeTextBetween(html, start, end);//Searching for running time.
start = "";
// Search for the URL of the poster image.
String imgUrl = giveMeTextBetween(html, start, end);
// Now, load that image!
poster = loadImage(imgUrl);
print("s");
}
String giveMeTextBetween(String s, String before, String after) {
before = "\"final_price\":";
after = ",\"hide_price\":";
// This function returns a substring between two substrings (before and after).
// If it can’t find anything it returns an empty string.
//String found = "";
// Find the index of before
int start = s.indexOf("\"final_price\":");
if (start == -1) {
return "";
}
// Move to the end of the beginning tag
// and find the index of the "after" String
start += before.length();
int end = s.indexOf(",\"hide_price\":", start);
if (end == -1) {
return "";
}
// Return the text in between
return s.substring(start, end);
}