2016-04-05 3 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 * = magnet]» выбирает ссылки, в которых атрибут href имеет строку «магнит» по ее значению.

Здесь вы можете прочитать больше о Atribute селекторов: attribute_selectors

Что вы хотите «#ResultSetItems h3.lvtitle»

Чтобы проверить свои селекторы есть это хороший РЕПЛ, который использует Jsoup, ту же библиотеку используемых webgrude Try jsoup

Смежные вопросы