Groovy异常。从seattletimes.com获取新闻时

时间:2018-04-09 22:53:21

标签: groovy

    **Exception thrown**
  

java.net.UnknownHostException:www.seattletimes.comseattle-news.rss at at   org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(UnknownSource)     在   org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(UnknownSource)     在org.apache.xerces.parsers.XML11Configuration.parse(未知来源)     在org.apache.xerces.parsers.XML11Configuration.parse(未知来源)     在org.apache.xerces.parsers.XMLParser.parse(未知来源)at   org.apache.xerces.parsers.AbstractSAXParser.parse(未知来源)at   org.apache.xerces.jaxp.SAXParserImpl $ JAXPSAXParser.parse(未知   来自News.getNews(SeattleNewsMash.groovy:14)at   新闻$ getNews.call(未知来源)at   SeattleNewsMash.run(SeattleNewsMash.groovy:105)

CODE

@Grab ('org.codehaus.groovy.modules.http-builder:http-builder:0.7.1')
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.ContentType
import groovyx.net.http.Method
import groovyx.net.http.HttpURLClient
import groovy.util.slurpersupport.GPathResult
import org.ccil.cowan.tagsoup.Parser



class News {

  String base = 'http://www.seattletimes.com'
  def getNews(int count) {
  def items = new XmlParser().parse(base + 'seattle_news.rss').channel[0].item[0..count]
        return items
    }
}


    // body of script
        def news = new News()
        def SeattleStories = news.getNews(3)
        println "Seattle News (unformatted):"
        println SeattleStories
        println "-----------------------------" 

1 个答案:

答案 0 :(得分:1)

它试图联系主持人" www.seattletimes.comseattle-news.rss",它们并不存在。您可能需要在" www.seattletimes.com"之间添加斜杠(至少)。和" seattle-news.rss"当您创建XmlParser