2016-04-05 10 views
1

私は最近、ウェブページの一部のコンテンツをスクレイプするためにWebGrudeを使用しました。それから私はe-bayからいくつかの検索結果を掻き集めようとしました。ここで試したものWebGrudeを使用して検索結果をスクラップする方法は?

@Page("http://www.ebay.com/sch/{0}") 
public class PirateBay { 

    public static void main(String[] args) { 
     //Search calls Browser, which loads the page on a PirateBay instance 
     PirateBay search = PirateBay.search("iPhone"); 

     while (search != null) { 
      search.magnets.forEach(System.out::println); 
      search = search.nextPage(); 
     } 
    } 

    public static PirateBay search(String term) { 
     return Browser.get(PirateBay.class, term); 
    } 

    private PirateBay() { 
    } 

    /* 
* This selector matches all magnet links. The result is added to this String list. 
* The default behaviour is to use the rendered html inside the matched tag, but here 
* we want to use the href value instead. 
*/ 
    @Selector(value = "#ResultSetItems a[href*=magnet]", attr = "href") 
    public List<String> magnets; 

/* 
* This selector matches a link to the next page result, wich can be mapped to a PirateBay instance. 
* The Link next gets the page on the href attribute of the link when method visit is called. 
*/ 
    @Selector("a:has(img[alt=Next])") 
    private Link<PirateBay> next; 

    public PirateBay nextPage() { 
     if (next == null) 
      return null; 
     return next.visit(); 
     } 
    } 

結果は空です。これを使用して検索結果をどうやって削ることができますか?

答えて

0

セレクタ "#ResultSetItems a [href * =磁石]"は、href属性の値に文字列 "磁石"があるリンクを選択します。ここで

あなたはAtributeセレクタについての詳細を読むことができます:attribute_selectors

何がしたいことは

があなたのセレクタをテストするにはJsoup、同じライブラリを使用して、この素敵なREPLがある「#ResultSetItemsがh3.lvtitle」でありますwebgrudeによって使用されるTry jsoup

関連する問題