HTMLRequests from multiple pages
in
Contributed Library Questions
•
1 year ago
Can I use SimpleML to parse HTML from multiple pages? If so how do I code netEvent to recive text from the multiple HTMLRequests?
Here we are trying to get movie titles from 3 seperate sites. ANY help regarding this is hugely appreciated :)
import simpleML.*;
String[] boxArray;
String[] filmArray;
String[] metaArray;
String boxHtml ="";
String filmHtml ="";
String metaHtml ="";
HTMLRequest boxRequest;
HTMLRequest filmRequest;
HTMLRequest metaRequest;
void setup() {
boxRequest = new HTMLRequest(this, "http://boxofficemojo.com/monthly/?view=releasedate&yr=2011&month=11");
htmlrequest.makeRequest();
filmRequest = new HTMLRequest(this, "http://www.filmcritic.com/top-rated#critics");
filmRequest.makeRequest();
metaRequest = new HTMLRequest(this, "http://www.metacritic.com/browse/movies/release-date/theaters/userscore?view=detailed");
metaRequest.makeRequest();
}
void draw() {
}
void boxEvent(HTMLRequest answer) {
String boxHtml = answer.readRawSource();
int from = 1;
int pos = 0;
for (int i = 0; i <= 4; i++) {
while ( (pos = boxHtml.indexOf ("><a href=\"/movies/?id", from)) <= 19995) {
int startTitle = boxHtml.indexOf("\">", pos) + 2;
int endTitle = boxHtml.indexOf("</a>", startTitle);
String title = boxHtml.substring(startTitle, endTitle);
from = boxHtml.indexOf("</a>", pos + 1);
boxArray[i] = title;
break;
}
}
}
void filmEvent(filmRequest answer) {
String filmHtml = answer.readRawSource();
int from = 1;
int pos = 0;
for (int i = 0; i <= 4; i++) {
while ( (pos = filmHtml.indexOf ("<td><a href=\"", from))<= 24952) {
int startTitle = filmHtml.indexOf("\">", pos) + 2;
int endTitle = filmHtml.indexOf("</a>", startTitle);
String title = filmHtml.substring(startTitle, endTitle);
from = filmHtml.indexOf("</a>", pos + 1);
filmArray[i] = title;
break;
}
}
}
void metaEvent(metaRequest answer) {
String metaHtml = answer.readRawSource();
int from = 1;
int pos = 0;
for (int i = 0; i <= 4; i++) {
while ( (pos = metaHtml.indexOf ("<a href=\"/movie/", from))<=31215) {
int startTitle = metaHtml.indexOf("\">", pos) + 2;
int endTitle = metaHtml.indexOf("</a>", startTitle);
String title = metaHtml.substring(startTitle, endTitle);
from = metaHtml.indexOf("</a>", pos + 1);
metaArray[i] = title;
break;
}
}
}
Here we are trying to get movie titles from 3 seperate sites. ANY help regarding this is hugely appreciated :)
import simpleML.*;
String[] boxArray;
String[] filmArray;
String[] metaArray;
String boxHtml ="";
String filmHtml ="";
String metaHtml ="";
HTMLRequest boxRequest;
HTMLRequest filmRequest;
HTMLRequest metaRequest;
void setup() {
boxRequest = new HTMLRequest(this, "http://boxofficemojo.com/monthly/?view=releasedate&yr=2011&month=11");
htmlrequest.makeRequest();
filmRequest = new HTMLRequest(this, "http://www.filmcritic.com/top-rated#critics");
filmRequest.makeRequest();
metaRequest = new HTMLRequest(this, "http://www.metacritic.com/browse/movies/release-date/theaters/userscore?view=detailed");
metaRequest.makeRequest();
}
void draw() {
}
void boxEvent(HTMLRequest answer) {
String boxHtml = answer.readRawSource();
int from = 1;
int pos = 0;
for (int i = 0; i <= 4; i++) {
while ( (pos = boxHtml.indexOf ("><a href=\"/movies/?id", from)) <= 19995) {
int startTitle = boxHtml.indexOf("\">", pos) + 2;
int endTitle = boxHtml.indexOf("</a>", startTitle);
String title = boxHtml.substring(startTitle, endTitle);
from = boxHtml.indexOf("</a>", pos + 1);
boxArray[i] = title;
break;
}
}
}
void filmEvent(filmRequest answer) {
String filmHtml = answer.readRawSource();
int from = 1;
int pos = 0;
for (int i = 0; i <= 4; i++) {
while ( (pos = filmHtml.indexOf ("<td><a href=\"", from))<= 24952) {
int startTitle = filmHtml.indexOf("\">", pos) + 2;
int endTitle = filmHtml.indexOf("</a>", startTitle);
String title = filmHtml.substring(startTitle, endTitle);
from = filmHtml.indexOf("</a>", pos + 1);
filmArray[i] = title;
break;
}
}
}
void metaEvent(metaRequest answer) {
String metaHtml = answer.readRawSource();
int from = 1;
int pos = 0;
for (int i = 0; i <= 4; i++) {
while ( (pos = metaHtml.indexOf ("<a href=\"/movie/", from))<=31215) {
int startTitle = metaHtml.indexOf("\">", pos) + 2;
int endTitle = metaHtml.indexOf("</a>", startTitle);
String title = metaHtml.substring(startTitle, endTitle);
from = metaHtml.indexOf("</a>", pos + 1);
metaArray[i] = title;
break;
}
}
}
1