Vaadin : CustomLayout don't generate <div> content - java

I'm using Vaadin 7. When I try to add html content to CustomLayout it does not generate a paragraph inside a div element. Here is the input :
<div style="margin-top: 10px; padding-left: 50px;" class="col-lg-10">
<div class="bs-component">
<ul class="nav nav-pills">
<li class="active"><a href="#Myprofile" class="active"
data-toggle="tab">Profile</a></li>
<li class="">setting</li>
<li class="">Tasks</li>
</ul>
<div class="tabbable">
<div class="tab-content">
<div id="Myprofile" location="Myprofile" class="tab-pane active"></div>
<div id="setting" location="setting" class="tab-pane">
<p>My paragraph</p>
</div>
</div>
</div>
</div>
In java I use this :
String html; //This var contain my input
InputStream is = new ByteArrayInputStream(html.getBytes());
CustomLayout custom = null;
try {
custom = new CustomLayout(is);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Finaly I add the customLayout to my mainLayout. When I run the application I get this output :
<div style="margin-top: 10px; padding-left: 50px;" class="col-lg-10">
<div class="bs-component">
<ul class="nav nav-pills">
<li class="active"><a href="#Myprofile" class="active"
data-toggle="tab">Profile</a></li>
<li class="">setting</li>
<li class="">Tasks</li>
</ul>
<div class="tabbable">
<div class="tab-content">
<div id="Myprofile" location="Myprofile" class="tab-pane active"></div>
<div id="setting" location="setting" class="tab-pane">
</div>
</div>
</div>
</div>
My paragraph inside div with id=setting was not generated by Vaadin. Any Ideas to fix this problem ?

I found the source of the problem. I removed the location="setting" part in the div element and it worked. I don't know why It does that. Probably because CustomLayout when generating the html looks for elements to put in the location, if it does not find one it clean all the element content.

Don't you need the location="setting" attribute? Don't you insert a component for that attribute?

Related

How to select two (or more) HTML elements that exist at the same tree level with Jsoup?

I'm working on a project and I faced a problem. I need to scrape data from the website that contains following HTML code:
<div class="lin-curso" style="border: 0;">
<div class="lin-area-c3">
Vagas 2017
</div>
</div>
<div class="box10">
<div class="lin-area-c1">
L160
</div>
<div class="lin-area-c2">
Acupuntura
</div>
<div class="lin-area-c3">
[Lic-1º cic]
</div>
</div>
<div class="lin-curso">
<div class="lin-curso-c1">
</div>
<div class="lin-curso-c2">
3155
</div>
<div class="lin-curso-c3">
Instituto Politécnico de Setúbal - Escola Superior de Saúde
</div>
<div class="lin-curso-c4">
20
</div>
</div>
<br>
<div class="box10">
<div class="lin-area-c1">
9059
</div>
<div class="lin-area-c2">
Administração e Gestão de Empresas
</div>
<div class="lin-area-c3">
[Lic-1º cic]
</div>
</div>
<div class="lin-curso">
<div class="lin-curso-c1">
</div>
<div class="lin-curso-c2">
2270
</div>
<div class="lin-curso-c3">
Universidade Católica Portuguesa - Faculdade de Ciências Económicas e Empresariais
</div>
<div class="lin-curso-c4">
n.d.
</div>
</div>
<br>
<div class="box10">
<div class="lin-area-c1">
8056
</div>
<div class="lin-area-c2">
Administração e Gestão Pública
</div>
<div class="lin-area-c3">
[Lic-1º cic]
</div>
</div>
<div class="lin-curso">
<div class="lin-curso-c1">
</div>
<div class="lin-curso-c2">
4275
</div>
<div class="lin-curso-c3">
Instituto Superior de Ciências da Administração
</div>
<div class="lin-curso-c4">
20
</div>
</div>
<br>
<div class="box10">
<div class="lin-area-c1">
8194
</div>
<div class="lin-area-c2">
Administração da Guarda Nacional Republicana
</div>
<div class="lin-area-c3">
[Mest Integ]
</div>
</div>
<div class="lin-curso">
<div class="lin-curso-c1">
</div>
<div class="lin-curso-c2">
7510
</div>
<div class="lin-curso-c3">
Academia Militar
</div>
<div class="lin-curso-c4">
n.d.
</div>
</div>
<br>
<div class="box10">
<div class="lin-area-c1">
9672
</div>
<div class="lin-area-c2">
Administração e Marketing
</div>
<div class="lin-area-c3">
[Lic-1º cic]
</div>
</div>
BOX10 and line-curso should form an element and they don't.
Because in some lines there is only one BOX10 for one Lin-curso but there are lines that are like Lin-curso for one Box10 , if Box10 and Lin-curso were an element there wouldn't be a problem , is there a way I can associate those two ?
EDIT: The website link is this : http://www.dges.gov.pt/guias/indcurso.asp?letra=A
And the element is the ".inside"
Solution to this problem is fairly easy when you use sibling selector. In your case div with class box10 plays role of a header in the table and sibling divs with class lin-curso play role of table data rows. I would suggest firstly selecting all divs with class box10:
Elements boxes = doc.select("div.box10");
Then you can iterate over boxes and do two major things:
Extract data you are interested in from this div (it contains 3 child nodes, divs with classes lin-area-c1, lin-area-c2 and lin-area-c3)
Select sibling nodes with class lin-curso and extract data from them.
Jsoup provides a method called Element.nextElementSibling() that return sibling element to the element you called this method on. So when you call it on element div.box10 you will get sibling element div.lin-curso.
Sibling in this case means a node immediately following the specified node at the same tree level.
Exemplary solution
Below you can find exemplary code that parses given website and prints table to the console output:
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
final class TestMain {
public static void main(String[] args) throws IOException {
Document doc = Jsoup.connect("http://www.dges.gov.pt/guias/indcurso.asp?letra=A").get();
Elements boxes = doc.select("div.box10");
for (Element box : boxes) {
String linAreaC1 = box.select(".lin-area-c1").text();
String linAreaC2 = box.select(".lin-area-c2").text();
String linAreaC3 = box.select(".lin-area-c3").text();
System.out.printf("%s: %s %s%n", linAreaC1, linAreaC2, linAreaC3);
Element linCurso = box.nextElementSibling();
while (linCurso.hasClass("lin-curso")) {
String linCursoC2 = linCurso.select(".lin-curso-c2").text();
String linCursoC3 = linCurso.select(".lin-curso-c3").text();
String linCursoC4 = linCurso.select(".lin-curso-c4").text();
System.out.printf("%s\t%s\t%s%n", linCursoC2, linCursoC3, linCursoC4);
linCurso = linCurso.nextElementSibling();
}
System.out.println("==============================");
}
}
}
I hope it helps.

Locating elements in <li> using selenium webdriver with java

I need to locate each item and click on it.
I tired this:
List<WebElement> allTournaments = driver.findElements(By.xpath("//*[#id='main-section']/div/div/section/div[1]/ul/li/div/div[1]/div"));
for (WebElement tournament : allTournaments) {
tournament.click();
}
But got the error "element not visible"
The xpath of first element is //[#id='main-section']/div/div/section/div1/ul/li1/div/div1/div
xpath of second element is //[#id='main-section']/div/div/section/div1/ul/li[2]/div/div1/div
like wise..
can anybody help..?
HTML:
<div class="header-toggle-area">
<div class="header-notification-area text-right ng-scope" ng-controller="notificationController">
</header>
<!--HEADER ENDS-->
<div class="content-wrap" style="padding-top: 60px;">
<aside id="main-sidebar">
<!--MAIN SIDEBAR ENDS-->
<main id="main-section">
<div class="main-content">
<div class="ng-scope" ng-controller="NewTournamentsController as tournaments">
<header class="member-title dt-title-main">
<section class="dashboard-tournaments-listing">
<div class="" ng-show="tournaments.Page==1">
<ul class="row dashboard-listing">
<!-- ngRepeat: running in tournaments.runningTournaments -->
<li class="dashboard-listing-items ng-scope" ng-repeat="running in tournaments.runningTournaments" style="">
<div class="dtslider-block">
<div class="dtslider-content">
<img ng-src="../../category/categoryDefault.jpg" alt="slider" src="../../category/categoryDefault.jpg"/>
<div class="hover-contents">
<div class="hc-timer">
<p> Tournament ends in </p>
<div class="hct-ticker ng-binding"> 04:30 - 26/11/16 </div>
</div>
<div class="hc-details">
<div class="hcd-block ng-hide" ng-show="running.JoinedPlayers>0">
<ul class="hc-icons">
</div>
</div>
</div>
Check if each element is visible and clickable as follows:
for (WebElement tournament : allTournaments) {
if (tournament.isDisplayed()
&& ExpectedConditions.elementToBeClickable(tournament).equals(true)) {
tournament.click();
}
}

How to load data dynamically on tab click from controller in spring mvc in same jsp page?

I am working with Ajax/jquery to reload a division of the page after clicking on a tab, but when I am running the code new jsp is displaying...
JSP page
<ul class="nav nav-tabs tabs-up" id="friends">
<li> Contacts </li>
<li> Friends list</li>
<li>Awaiting request</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="area">
<%# include file="areas.jsp" %>
</div>
<div class="tab-pane" id="friends_list">
</div>
<div class="tab-pane urlbox span8" id="awaiting_request">
</div>
</div>
ajax call
$('[data-toggle="tabajax"]').click(function(e) {
var $this = $(this),
loadurl = $this.attr('href'),
targ = $this.attr('data-target');
$.get(loadurl, function(data) {
$(targ).html(data);
});
$this.tab('show');
return false;
});
Controller
#RequestMapping("/area")
public ModelAndView noticesAjaxRequest(ModelMap model) {
String str="a";
return new ModelAndView("areas", "str", str);
}
But when i am running this code I am only getting areas.jsp as output.
The problem is that you still have href attributes in your <a> elements.
Change <a href="/area" ...
to <a href="" ...
You have to store the link in another attribute (e.g. data-href), then.

Parse .phtml file in Java

I'm trying to parse a phtml file from a project and save modifications to this file with Java. I actually use Jsoup API to parse this file. My problem is the saving step. Lets see an example :
PHTML FILE :
<div id="header">
<div id="logo">
<img src="images/logo.png" id="logo_pic" />
</div>
<div id="welcome">
<span id="welcome_title">
</span>
</div>
</div>
Java parsing :
File testFile = new File("C:\\Users\\root\\Desktop\\test.phtml");
try {
Document doc = Jsoup.parse(testFile, "UTF-8");
Element essai = doc.getElementById("welcome_title");
essai.appendText("Application NAME!");
PrintWriter writer = new PrintWriter(testFile, "UTF-8");
writer.write(doc.html());
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Result i want to have should be like this :
<div id="header">
<div id="logo">
<img src="images/logo.png" id="logo_pic" />
</div>
<div id="welcome">
<span id="welcome_title">
Application NAME!
</span>
</div>
</div>
Result i have for the moment :
<html>
<head></head>
<body>
<div id="header">
<div id="logo">
<img src="images/logo.png" id="logo_pic" />
</div>
<div id="welcome">
<span id="welcome_title"> Application NAME!</span>
</div>
</div>
</body>
</html>
My problem is that i must keep a phtml format with only div elements for my application. How can i reach the good result? Any idea? Thx for help!
Do this:
writer.write(essai.outerHtml());
instead of
writer.write(doc.html());

Jsoup getElementsByClass gives size 0 Elements

I'm trying to write a program that fetches weather information from weather.com by using JSoup. This is what I have so far:
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.jsoup.Jsoup;
public class WeatherComHandler {
private Element ForeCastDiv;
public static void main(String[] args) {
WeatherComHandler wch = new WeatherComHandler("http://www.weather.com/weather/today/Brussels+BEXX0005:1:BE");
wch.getTodaysForeCast();
}
public WeatherComHandler(String url) {
getForeCastDiv(url);
}
private void getForeCastDiv(String url) {
try {
Document doc = Jsoup.connect(url).get();
ForeCastDiv = doc.getElementById("wx-forecast-container");
} catch(Exception e) {
e.getStackTrace();
}
}
public void getTodaysForeCast() {
System.out.println(ForeCastDiv.toString());
System.out.println(ForeCastDiv.hasClass("wx-data-part wx-first"));
Elements todaysElements = ForeCastDiv.getElementsByClass("wx-data-part wx-first");
System.out.println(todaysElements.size());
}
}
This is the output:
<div id="wx-forecast-container">
<div class="wx-today wx-module wx-grid3of6">
<div class="wx-title-container">
<h2 class="wx-title"><img src="http://i.imwx.com/common/My.png" /> Forecast for Today</h2>
<div class="wx-updated">
Updated: Oct 28, 5:45pm Local Time
</div>
<div class="wx-promo-links wx-cond wx-severe wx-severe-0">
<ul class="wx-links">
<li class="wx-icon wx-cond wx-desktop"> <a class="wx-icon wx-cond wx-desktop" href="/apps/desktop-weather" location="" from="today_promo_1" title="Weather on my Desktop">Desktop App</a> </li>
</ul>
</div>
</div>
<div class="wx-weather-details">
<div class="wx-timepart-title wx-first">
Right Now
<div class="wx-module wx-grid1of6 wx-weather wx-love-module wx-cond-bg">
<div class="wx-module-inner">
<div class="wx-icon wx-social wx-balloon-wt-lt wx-clickable wx-love-ugh" data-good="true" data-share-trx="" data-share-icon="http://s.imwx.com/img/common/social/lmw-love.jpg" title="Love My Weather" data-share-desc="It's 55°F, Clear">
<div class="wx-icon wx-social wx-heart"></div>
<h4 data-share-title="Love! Right now in Brussels, Belgium"></h4>
</div>
<div class="wx-icon wx-social wx-balloon-wt-rt wx-clickable wx-love-ugh" data-good="false" data-share-trx="" data-share-icon="http://s.imwx.com/img/common/social/lmw-ugg.jpg" title="Don't Love My Weather" data-share-desc="It's 55°F, Clear">
<h4 data-share-title="Ugh! Right now in Brussels, Belgium"></h4>
</div>
</div>
</div>
</div>
<div class="wx-timepart-title">
Earlier Today
</div>
<div class="wx-timepart-title">
Tonight
</div>
<div class="wx-data-part wx-first">
<img src="http://s.imwx.com/v.20131006.214956/img/wxicon/120/31.png" height="120" width="120" alt="Clear" class="wx-weather-icon" />
</div>
<div class="wx-data-part">
<img src="http://s.imwx.com/v.20131006.214956/img/wxicon/120/34.png" height="120" width="120" alt="Fair / Windy" class="wx-weather-icon" />
</div>
<div class="wx-data-part">
<img src="http://s.imwx.com/v.20131006.214956/img/wxicon/120/29.png" height="120" width="120" alt="Partly Cloudy" class="wx-weather-icon" />
</div>
<div class="wx-data-part wx-first">
<div class="wx-temperature">
<span itemprop="temperature-fahrenheit">55</span>
<span class="wx-degrees">°<span class="wx-unit">F</span></span>
</div>
<div class="wx-temperature-label">
FEELS LIKE
<span itemprop="feels-like-temperature-fahrenheit">55</span>°
</div>
</div>
<div class="wx-data-part">
<div class="wx-temperature">
62
<span class="wx-degrees">°</span>
</div>
<div class="wx-temperature-label">
HIGH AT 11:45 AM
</div>
</div>
<div class="wx-data-part">
<div class="wx-temperature">
47
<span class="wx-degrees">°</span>
</div>
<div class="wx-temperature-label">
LOW
</div>
</div>
<div class="wx-data-part wx-first">
<div class="wx-phrase ">
Clear
</div>
<div class="wx-obs-qualifier ">
<span class="wx-hide" itemprop="observation-qualifier">OQ1190</span>
<span class="wx-hide" itemprop="observation-qualifier-severity">2</span>
<span itemprop="observation-qualifier-phrase">Locations nearby are reporting rain with wind.</span>
</div>
</div>
<div class="wx-data-part">
<div class="wx-phrase ">
Fair / Windy
</div>
</div>
<div class="wx-data-part">
<div class="wx-phrase ">
Partly Cloudy
</div>
</div>
<div class="wx-data-part wx-first">
<h6 class="wx-label">Past 24-hr Precip:</h6>
<div class="wx-data">
0.34 in
<span class="wx-estimated">(est.)</span>
</div>
</div>
<div class="wx-data-part">
<h6 class="wx-label"></h6>
<div class="wx-data"></div>
</div>
<div class="wx-data-part">
<h6 class="wx-label">Chance of <span class="wx-firstletter">rain</span></h6>
<div class="wx-data">
<span class="wx-icon wx-raindrop"></span>20%
</div>
</div>
<div class="wx-collapsible">
<div class="wx-data-part wx-first wx-wind">
<h6 class="wx-label">Wind:</h6>
<div class="wx-data">
<div class="wx-icon wx-dir-arrow-sm wind-dir-SW"></div>
<div class="wx-wind-label">
SW at 17 mph
</div>
</div>
</div>
<div class="wx-data-part wx-wind">
<h6 class="wx-label"></h6>
<div class="wx-data">
<div class="wx-wind-label"></div>
</div>
</div>
<div class="wx-data-part wx-wind">
<h6 class="wx-label">Wind:</h6>
<div class="wx-data">
<div class="wx-icon wx-dir-arrow-sm wind-dir-SW"></div>
<div class="wx-wind-label">
SW at 18 mph
</div>
</div>
</div>
<div class="wx-data-part wx-first">
<h6 class="wx-label">Humidity:</h6>
<div class="wx-data">
76%
</div>
</div>
<div class="wx-data-part">
<h6 class="wx-label"></h6>
<div class="wx-data"></div>
</div>
<div class="wx-data-part">
<h6 class="wx-label">Humidity:</h6>
<div class="wx-data">
82%
</div>
</div>
<div class="wx-data-part wx-first">
<h6 class="wx-label">UV Index:</h6>
<div class="wx-data">
0 - Low
</div>
</div>
<div class="wx-data-part">
<h6 class="wx-label"></h6>
<div class="wx-data"></div>
</div>
<div class="wx-data-part"></div>
<div class="wx-data-part wx-first ">
<h6 class="wx-label"></h6>
<p class="wx-text"></p>
</div>
<div class="wx-data-part ">
<h6 class="wx-label"></h6>
<p class="wx-text"></p>
</div>
<div class="wx-data-part ">
<h6 class="wx-label">Tonight:</h6>
<p class="wx-text">Partly cloudy skies. Low 47F. Winds SW at 15 to 25 mph.</p>
</div>
<div class="wx-astro-neighbor">
<div class="wx-data-part wx-first">
<h6 class="wx-label">Pressure:</h6>
<div class="wx-data">
<span itemprop="barometric-pressure-incheshg"> 29.59 in </span>
<span class="wx-icon wx-dir-arrow-sm wx-pressure-steady"></span>
</div>
</div>
<div class="wx-data-part wx-first wx-dewpoint">
<h6 class="wx-label">Dew Point: <span class="wx-icon wx-long wx-info"> <i>Humidity becomes more noticeable as the dew point rises above 60°F. Readings above 75°F can feel stifling.</i> </span> </h6>
<div class="wx-data">
47°
</div>
</div>
<div class="wx-data-part wx-first">
<h6 class="wx-label">Visibility:</h6>
<div class="wx-data">
6.0 mi
</div>
</div>
</div>
<div class="wx-astro-details">
<h3 class="wx-astro-title">Sun & Moon</h3>
<dl class="wx-first">
<dt>
Sunrise:
</dt>
<dd>
7:28 am
</dd>
<dt>
Sunset:
</dt>
<dd>
5:25 pm
</dd>
</dl>
<dl>
<dt>
Moonrise:
</dt>
<dd>
12:27 am
</dd>
<dt>
Moonset:
</dt>
<dd>
2:32 pm
</dd>
</dl>
<dl class="wx-moonphase-container">
<dt>
Moonphase:
</dt>
<dd>
<div class="wx-icon wx-moonphase wx-moon-23"></div>
<div class="wx-moonphase-label">
Waning Crescent
</div>
</dd>
</dl>
</div>
</div>
</div>
<div class="wx-toggle-collapsible-container">
<div class="wx-toggle-collapsible wx-clickable">
<div class="wx-control wx-expand-control" tracktype="action" trackstr="today_rightnow_showmore">
<span class="wx-icon wx-arrow wx-mb-lg-dn"></span>Open Weather Details
</div>
<div class="wx-control wx-collapse-control wx-hide" tracktype="action" trackstr="today_rightnow_showless">
<span class="wx-icon wx-arrow wx-mb-lg-up"></span>Close Weather Details
</div>
</div>
</div>
<div class="wx-pagination-linkers">
<div class="wx-next-linker">
<ul class="wx-links">
<li class=""> <a class="" href="/weather/hourbyhour/graph/Brussels+BEXX0005:1:BE" location="" from="today_rightnow-Today_tempGraph_1" title="">Hourly Forecast</a> </li>
</ul>
</div>
</div>
</div>
<script>$("#wx-icon wx-long wx-info").attr('title','This is the hover-over text');</script>
<div id="wunderground-lightbox" class="wx-dialog">
<div class="wx-close" title="Close">
<div class="wx-icon"></div>
</div>
</div>
<div class="wx-combinedPromo wx-module wx-grid3of6">
<div class="wx-commuter-promo" data-classname="wx-grid-2" from="today-commuterpromo" data-layers="traffic,weather" data-locationinus="false" data-backgroundimageurl="" data-location-zoom="10" data-location-latitude="50.85045" data-location-longitude="4.34878">
<div class="wx-commute-promo-callout-title">
<div class="wx-titleIconHolder">
<img class="wx-titleIcon" src="http://s.imwx.com/img/module/TrafficCams_16x16.png" />
</div>
<div class="wx-titleText">
NEW! Traffic & Commuter Forecast
</div>
</div>
</div>
</div>
<div class="wx-clear"></div>
<div class="wx-scroll-tracking wx-scroll-pres" data-modulecode="ScrollTracking1_Today" data-location="BEXX0005:1:BE" data-groupname="weblocal"></div>
<div class="wx-free-title ">
<h3>Latest Stories</h3>
</div>
<div id="wx-rightnowsecond-container">
<div id="wx-rightnow-container">
<div class="wx-module wx-mod1 wx-corsican wx-1x155M wx-render-mode" id="mod_4" data-vr-zone="today_beta_Media_top2">
<div class="wx-inner" data-vr-contentbox=""></div>
</div>
<div class="wx-module wx-mod1 wx-corsican wx-1x155M wx-render-mode" id="mod_5" data-vr-zone="today_beta_Media_top1">
<div class="wx-inner" data-vr-contentbox=""></div>
</div>
</div>
<div class="wx-module wx-trending-stories wx-tabbed-content wx-grid2of6">
<div class="wx-inner">
<h2 class="wx-title">Most Popular</h2>
<ul class="wx-tabs" data-vr-zone="Most Popular">
<li class="wx-tab wx-active" data-tab="today" data-vr-contentbox="">Today</li>
<li class="wx-tab wx-clickable" data-tab="this_week" data-vr-contentbox="">This Week</li>
</ul>
<ul class="wx-tab-content" data-tab="today" data-vr-zone="Most Popular">
<li data-vr-contentbox="">Superstorm Sandy: Then and Now (EXCLUSIVE PHOTOS)</li>
<li data-vr-contentbox="">Eerie Nighttime Shots of Abandoned America</li>
<li data-vr-contentbox="">Astounding Fall Photos That Will Make You Say 'Wow!'</li>
<li data-vr-contentbox="">Nightmares Fear Factory: Terrified Reactions at Haunted House (PHOTOS)</li>
<li data-vr-contentbox="">The 15 Worst U.S. Cities for Asthma</li>
<li data-vr-contentbox="">Shocking End to Shark Attack <span class="wx-icon wx-video wx-trending-video"></span></li>
<li data-vr-contentbox="">Gigantic Hornets Are Breeding <span class="wx-icon wx-video wx-trending-video"></span></li>
<li data-vr-contentbox="">18-Foot WHAT? <span class="wx-icon wx-video wx-trending-video"></span></li>
</ul>
<ul class="wx-tab-content" data-tab="this_week" style="display:none;" data-vr-zone="Most Popular">
<li data-vr-contentbox="">Superstorm Sandy: Then and Now (EXCLUSIVE PHOTOS)</li>
<li data-vr-contentbox="">Nightmares Fear Factory: Terrified Reactions at Haunted House (PHOTOS)</li>
<li data-vr-contentbox="">Eerie Nighttime Shots of Abandoned America</li>
<li data-vr-contentbox="">8 Deadly Venomous Creatures and Those Who've Survived (PHOTOS)</li>
<li data-vr-contentbox="">Astounding Fall Photos That Will Make You Say 'Wow!'</li>
</ul>
</div>
</div>
</div>
<div class="wx-map wx-cc-map wx-grid3of6 wx-module pagelet " data-severelocation="false" data-location="BEXX0005" data-location-type="1" data-overlay="" data-zoom="" data-tropical="" data-mapsize="3" data-fragid="frag_newccMap_166739" data-modulecode="beta_CCMap" data-pageid="62288">
</div>
</div>
false
0
The problem is getTodaysForeCast() keeps saying that the size of todaysElements is 0, which it shouldn't be. Could anyone explain me why this is happening or what I'm doing wrong?
thanks in advance.
Jsoup will not accept two combined classes in the getElementsByClass method. Try something like:
Elements todaysElements = ForeCastDiv.getElementsByAttributeValueContaining("class", "wx-data-part wx-first");
You're passing two separate class names (separated by a space) to both hasClass() and getElementsByClass(), both of which can only handle one class at a time.
Try using select() instead. It allows you to use complex CSS selectors to find elements, like this:
ForeCastDiv.select(".wx-data-part.wx-first")

Categories