2015-05-14 94 views
0

不知有什麼辦法可以從這樣的代碼片段:JSOUP提取多種元素的同時

<div class="container "> 
         <h2 class="job"> 
          <a href="/work/android-developer/madrid/11537332" rel="nofollow" 
          title="job Android Developer" class="job-offer "> 
           Android Developer 
          </a> 
         </h2> 
          <h3 class="company"> 
            <a href="/emp/nbc/133192"> 
             NBC Corp. 
           </a> 
         </h3> 
       </div> 

文本Android developer和一次性NBC Corp.

類似doc.select("h2,h3.p-job-title,p-name-company a[href]");不起作用。我也試過doc.select("h2.p-job-title a[href], h3.p-name company a[href]");

請幫忙!

編輯:我發現使用doc.select("h2.p-job-title + h3.p-name.company");我可以提取所需的東西,但我需要的是h2內容+ h3內容在一行中,我的意思是「Android Developer NBC Corp.」。這樣,我得到:

「Android開發者」

「NBC公司」

+1

你爲什麼不能在連接字符串自己呢? – Timo

回答

2

文本Android developerNBC Corp.在一個鏡頭?

試試這個:

Elements es = doc.select("div.container"); 

for(Element e:es) 
{ 
System.out.println(e.select("h2").text()+"\t"+e.select("h3").text()); 

} 
+0

@EDMUNDO如果我的代碼適合你,請標記它。 – JavaFan