I'm new in the forum. I can't find a serious programming support site in my country, so i'll try my luck here. I'm having problems getting HTML source code from a precise site:http://www.meteoam.it/ta/previsione/110/magenta
I'm using this code:
Document document2 =Jsoup.connect("http://www.meteoam.it/ta/previsione/110/magenta").userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0").get();
Elements temp2 = document2.select("div.tab-content");
html = "";
i = 0;
for (Element movielist : temp2) {
i++;
html = (i + "|||" + movielist.getElementsByTag("td").html());
array3b[i] = html;
}
I'd like to get temperature infos so between:
<div class="tab-content">
<tr>INFO</tr>
<div>
Strange thing is that I'm not able to get any code from this website. Can somebody help me at least verifying if this site has a sort of protection?
Thanks in advance.
You're selecting too many table cells. The values you want are there but difficult to find. You can create better CSS selector to match only table cells you want. Try this code. Explanation in comments:
Document document2 = Jsoup.connect("http://www.meteoam.it/ta/previsione/110/magenta")
.userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0").get();
/* after analyzing HTML of this page I see we can find table by id "oggi" and get all TD cells */
Elements tableCells = document2.select("div#oggi td");
/* I see you want to keep the values in an array so I'm creating
an array of the size matching amount of table cells found */
String[] values = new String[tableCells.size()];
int i = 0;
for (Element td : tableCells) {
/* putting each cell text into the array */
values[i++] = td.text();
}
/* display collected values */
System.out.println("TEMP " + values[2]);
System.out.println("UMIDITÀ " + values[3]);
System.out.println("VENTO " + values[4]);
System.out.println("RAFFICHE " + values[5]);