2017-08-11 11 views
-6

私の質問は、画面上に出力されています。私はテーブルクラス= "gallerybig"からテキストとリンクを取得できません。ウェブサイトからのテキストとリンクを取得できませんjsoupを使用したhtml解析

ご質問がわからない場合は、[email protected]までご連絡ください。

コードのolxリンクを参照してください。そして、ソースコードをチェックしてください。

画像リンクを確認してください。

I want to get text and link from each table with class="gallerybig". there are 41 table so we have to run loop.

私は、NetBeans上でこれをruningています。

enter code here 
    Document doc; 
       try { 
      doc = (Document) Jsoup.connect("https://www.olx.in/sale/?view=galleryBig&page=4") 
        .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0") 
        .get(); 
      String roottable = "tbody > tr"; 
    Elements first = doc.select("body[class=offersview.standard.smallscreen.bodyIndent]"); 
    Elements table = first.select("table[class=gallerybig]"); 

     for(Element base : table){ 
    for (Element t1:base.select(roottable)){ 

    Elements td = t1.select("td[valign=top]"); 

Elements div = td.select("div[class=item.rel]"); 
Elements divinner = div.select("div[class=inner.brkword]"); 
Elements divclr = divinner.select("div[class=clr]"); 
Elements h4 = divclr.select("h4[class=normal.large.lheight24]"); 

Elements link = h4.select("a"); 
Elements select = link.select("a[href]"); 

Elements title = link.select("span"); 
String titles = title.text(); 

Elements pricetag = divclr.select("p[class=price.x-large]"); 
Elements strong = pricetag.select("strong[class=c000]"); 
String price = (String) strong.text(); 

Elements ptag = divclr.select("p[class=lheight18.color-1.margintop8]"); 
     for (Iterator<Element> it = ptag.iterator(); it.hasNext();) { 
      Element ype = it.next(); 
      String type = ype.text(); 
      System.out.println(type.toString()); 
      System.out.println("fg"); 


} 
    Elements span = ptag.select("span"); 
     String place = span.text(); 

     System.out.println(place); 
     System.out.println(titles); 
     System.out.println(price); 


     System.out.println(select); 
     } 

    } 



    } catch (IOException e) { 
     e.printStackTrace(); 


     } 

    } 

出力: - 実行: BUILD SUCCESSFUL(合計時間:2秒)

画面上の出力にあります。

+0

をし、問題がありますか? https://stackoverflow.com/help/mcveの下で私たちの質問を改善してください。 –

+0

[email protected]に私に連絡したい場合は – krunal

答えて

0

私が答だ:

Document doc; 
{ 
     try{ 
      doc = Jsoup.connect("https://www.olx.in/lucknow/sale/?search%5Bdescription%5D=1&view=galleryBig").get(); 
      Elements img = doc.select("div.mheight.tcenter img.fleft.rel.zi2"); 
     for(Element src : img){ 
      System.out.println("\nimg : " + src.attr("src")); 
     } 

     Elements links = doc.select("div.clr > h4.normal.large.lheight24 > a[href]"); 
     for (Element link : links) { 
      String classname = link.className().toString(); 
        if(classname.contains("link linkWithHash detailsLinkPromoted linkWithHashPromoted")){ 
         System.out.println("pro: yes "); 
        } 

        System.out.println(classname); 
        System.out.println("\nlink : " + link.attr("href")); 
        System.out.println("text : " + link.text()); 

     } 


     Elements price = doc.select("div.clr > p.price.x-large strong.c000"); 
     for (Element getprice: price){ 
      System.out.println("\nPrice : " + getprice.text()); 
     } 

     Elements typeandplace = doc.select("p.lheight18.color-1.margintop8"); 
     for (Element gettypeplace : typeandplace){ 
      System.out.println(" \nPlace : " + gettypeplace.text()); 
     } 



     } catch (IOException e) { 
      e.printStackTrace(); 
     } 



} 
関連する問題