I'm in front of a very big problem to me.. I'm parsing this page http://multiplayer.it/articoli/ with inside some articles.. As you can see, there are some informations i can parse: Tile, date of the article, comments and little preview of the article.
THE GOAL :
My goal is click on the article i parse(this operation it's already ok, i have the list with the informations i wrote below) and onClick
i want enter in the article itself to see the content. Example: if i click in the first article right now, it brings me at this URL: http://multiplayer.it/notizie/127771-peter-moore-getta-acqua-sul-fuoco-e-descrive-nintendo-come-un-grande-partner-per-ea.html with all content i need view. The appplication has to do the same.
THE PROBLEM I don't know how can do it. But parsing the url of each post i can know the absolute path of post. I can parse it in this way:
try {
Document doc = Jsoup.connect(BLOG_URL).get();
Elements links = doc.select("div.col-1-1 h2 a[href]");
for(Element sezione : links)
{
Log.d("Links", sezione.attr("abs:href"));
}
} catch (Exception e) {
Log.e("ERROR", "Parsing Error");
}
And it returns each href.
QUESTION
Is it possible knwoing the href parse each page content? (the 'p'
tag) Thanks
OnClick method
lista.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//What here?
}
});
jsoup
wouldn't handle your dynamic actions on a web page. You would need to use an API which can handle these dynamic executions - an example beingHtmlUnit
.Let's say you have a possibility all the links stored as part of a Java Collection instance like an
ArrayList
. If I try to parse the first url in the form of a specific method (which can be looped over to get the contents at runtime for all the url on your page dynamically):Using HtmlUnit
In the above code, it displays all the
<p>
available on the landing page. Below is the screenshot of the output:In the above code block, you have the ability to loop over all the anchor tags on the web page, and I choose a specific anchor link to get the resulting content:
You might want to right an appropriate logic to parse all the dynamic links on your page and display their contents.
EDIT:
You can try generating these dynamic scripts through htmlunitscripter Firefox plugin and customize it later to your needs too.