OSDN Git Service

79b3d032d99f9d831db9ebf865d334a467d25793
[coroid/NicoBrowser.git] / src / nicobrowser / util / ResultParse.groovy
1 /* $Id$ */
2
3 package nicobrowser.util
4 import org.cyberneko.html.parsers.SAXParser
5
6
7 class ResultParse {
8     List<nicobrowser.util.Result> parse(InputStream is){
9         def html = new XmlSlurper(new SAXParser()).parse(is)
10         def res = html.'**'.findAll{it.@class == 'vinfo_title'}
11
12         List<nicobrowser.util.Result> list = []
13         res.each{list += new nicobrowser.util.Result(
14                 it.@href[0].text().replaceAll('watch/',''),
15                 it.text())}
16
17         return list
18     }
19
20     TreeMap<Integer, String> getOtherPages(InputStream is){
21         def html = new XmlSlurper(new SAXParser()).parse(is)
22         def res = html.'**'.find{it.@class == 'pager'}
23         def map =[:]
24         res.TBODY.TR.TD.A.each{
25             try{
26                 def page = Integer.parseInt(it.text())
27                 def url = it.@href.text()
28                 map.put(page,url)
29             }catch(e){}
30         }
31         return map
32     }
33 }
34