-1

i've searched in all over the network but i didn't find something helpfull for me:

i'd like to get all "third" elements: (simplified)

<div class="first">
 <div class="second">
  <div data-type="container" style="display: block;"> ==$0
   <div class="third">
   <div class="third">
   <div class="third">

i'm actually using:

Elements rows = (doc.select("div.first div.second").select("[data-type="container"]") for (Element row : rows){ System.out.println(row); }

but my output is: <div data-type="container"></div>

event if i use:

Elements rows = (doc.select("div.first div.second").select("[data-type="container"]".select("div.third")

my output is empty.

seems that i cannot get into that data-type="container", is there a particoular method to do it?

thanks to all!

Flipper
  • 1
  • 1
  • 2
    Your code doesn't seem to be correct because of unescaped `"` in string and fact that you are surrounding attributes with quotes like `[data-type="container"]` which makes `"` part of value. Post your real code. – Pshemo Aug 15 '16 at 20:02
  • Also is it possible that you are trying to parse content which is dynamically added (by JavaScript)? If yes then Jsoup is not right tool since it is not browser emulator which could include JavaScript but simple HTML/XML parser. You would need something like Selenium web-driver. – Pshemo Aug 15 '16 at 20:03
  • If you don't want to post real code it is fine, but please make your examples correct. We don't want to waste time of errors which are not really related to your problem. Anyway since you are new user you may not know that to update your question you can use [edit] option placed under tags. – Pshemo Aug 15 '16 at 20:12
  • Thanks for the answer, i don't want to make you losing more time, thus i link you the website: http://www.livescore.com/soccer/2016-08-09/ i cannot parse, for example, Real Madrid. Seems Jsoup is blocked at data-type="container" level. thanks again. – Flipper Aug 16 '16 at 21:06
  • Like I guessed problem is that content of that page is not sent to you with HTML code, but is generated by JavaScript (which gets it in different call, to server and parse response in its own way). Jsoup is not tool for your job. You either want to use browser emulator or driver, or use other site which will give you API allowing your app to interact with it. Here is (quite old, so it may not be up to date) question about it http://stackoverflow.com/questions/13370914/uefa-fifa-scores-api. – Pshemo Aug 16 '16 at 21:41

2 Answers2

1

When I use your code I've got the following result by correcting the typo syntax pointed out by Pshemo :

<div data-type="container" style="display: block;">
  ==$0 
 <div class="third"></div> 
 <div class="third"></div> 
 <div class="third"></div> 
</div>

But if you only want the content of the div "container", you could use the following selector :

doc.select("div.first>div.second>div>*")

instead of

doc.select("div.first div.second").select("[data-type="container"]")

which make the following output:

<div class="third"></div>
<div class="third"></div>
<div class="third"></div>
Aurelien
  • 458
  • 1
  • 5
  • 13
  • Thanks for the answer, i don't want to make you losing more time, thus i link you the website: http://www.livescore.com/soccer/2016-08-09/ i cannot parse, for example, Real Madrid. Seems Jsoup is blocked at data-type="container" level. thanks again. – Flipper Aug 16 '16 at 21:08
1

The general format of you code is correct so it is possible that there is a syntax error somewhere (it's easier for us to find the issue if you c/p the exact code).

Elements rows = doc.select("div.first div.second")
        .select("[data-type=container]").select("div.third");
for (Element row : rows){
    System.out.println(row);
}

Alternately because all of the "third" nodes have the same class you could use getElementsByClass(String className).

Elements rows = doc.getElementsByClass("third");
for (Element row : rows){
    System.out.println(row);
}

Both will print out the following:

<div class="third"></div>
<div class="third"></div>
<div class="third"></div>
Arthur
  • 1,246
  • 1
  • 15
  • 19
  • Thanks for the answer, i don't want to make you losing more time, thus i link you the website: http://www.livescore.com/soccer/2016-08-09/ i cannot parse, for example, Real Madrid. Seems Jsoup is blocked at data-type="container" level. thanks again. – Flipper Aug 16 '16 at 21:08