Jsoup错误地关闭标记并将标记文本放在标记之外

时间:2013-02-20 16:58:02

标签: jsoup

我正在解析一个Feed,但它错误地关闭了一个标记

<link />http://wwww

以下是我从网址

获取HTML的代码
    Document doc = Jsoup.connect(pURL).get();
    doc.outputSettings().outline(false);
    doc.outputSettings().prettyPrint(false);
    String html = doc.html();

它提供以下XML

<!--?xml version="1.0" encoding="utf-8"?--><html><head></head><body><rss version="2.0">    <channel>
    <title>Fenopy rss</title>
    <link />http://fenopy.eu/ <----------@see this
    <description>Fenopy torrent rss</description>
    <language>en-us</language>

        <item>
        <title>Broken City 2013 CAMRip English</title>
        <guid ispermalink="true">http://fenopy.eu/torrent/broken+city+2013+camrip+english/OTU0MDI1MA</guid>
        <pubdate>Sun, 27 Jan 2013 19:23:21 GMT</pubdate>
        <category>Movies</category>
        <link />http://fenopy.eu/torrent/bnglish/OTU0MDI1MA <----------@see this
        <enclosure url="http://fenopy.eu/torrent/Broken-City-2013-CAMRip-English/OTU0MDI1MA==/download.torrent" length="783829383" type="application/x-bittorrent" />
        <description> Category: Movies&lt;br/&gt;Size: 747.5 MB&lt;br/&gt;Ratio: 60 seeds, 11 leechers&lt;br/&gt; </description>
        </item>

但是当我在浏览器中打开它时,它显示正确的xml

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" >    <channel>
    <title>Fenopy rss</title>
    <link>http://fenopy.eu/</link>
    <description>Fenopy torrent rss</description>
    <language>en-us</language>

        <item>
        <title>Broken City 2013 CAMRip English</title>
        <guid isPermaLink='true'>http://fenopy.eu/torrent/broken+city+2013+camrip+english/OTU0MDI1MA</guid>
        <pubDate>Sun, 27 Jan 2013 19:23:21 GMT</pubDate>
        <category>Movies</category>
        <link>http://fenopy.eu/torrent/broken+city+2013+camrip+english/OTU0MDI1MA</link>
        <enclosure url="http://fenopy.eu/torrent/Broken-City-2013-CAMRip-English/OTU0MDI1MA==/download.torrent" length="783829383" type="application/x-bittorrent" />
        <description><![CDATA[ Category: Movies<br/>Size: 747.5 MB<br/>Ratio: 60 seeds, 11 leechers<br/> ]]></description>
        </item>

我不知道发生了什么事。在Jsoup 1.7.2 jar中有任何错误吗? 帮助我...

1 个答案:

答案 0 :(得分:1)

这不是一个错误。您的GDATA响应内容类型为application/rss+xml,因此您必须指定Parser是XML解析器;否则,默认情况下,它是HTML解析器,其工作方式不同。

    // load Document
    Document doc = Jsoup.connect(URL_SOURCE).ignoreContentType(true).parser(Parser.xmlParser()).get();
  

//如果设置outline和prettyprint = true,那么你必须寻找   \ n和\ t字符,你必须删除它们,所以把它们弄错

    // config output
    doc.outputSettings().outline(false);
    doc.outputSettings().prettyPrint(false);

    // output result
    System.out.println(doc.html());

如果指定XML解析器,则<link>的结果会正确输出。