0

I was parsing a feed but it wrongly closes a tag

<link />http://wwww

Here is my code for getting HTML from a URL

    Document doc = Jsoup.connect(pURL).get();
    doc.outputSettings().outline(false);
    doc.outputSettings().prettyPrint(false);
    String html = doc.html();

It gives following 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>

but when I open it in browser it shows correct 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>

I don't know what's going on. is there any bug in Jsoup 1.7.2 jar? help me ...

4

1 回答 1

1

这不是一个错误。您的 GDATA 响应内容类型为application/rss+xml,因此您必须指定您的Parseris 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());

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

于 2013-02-24T13:42:56.740 回答