如何从Twitter搜索源获取纯文本结果?

时间:2009-12-27 14:08:32

标签: html xml silverlight rss twitter

我正在编写一个简单的Twitter示例,通过以下方式读取Twitter搜索RSS源:

http://search.twitter.com/search.rss

这很有效,除了其中的描述包含HTML,如粗体标签和链接标签,我通过以下方式查看了Atom提要:

http://search.twitter.com/search.atom

它在描述中也有HTML,是否有一个版本只包含推文的纯文本?文档有点模糊,加上格式列表中缺少RSS,即使这样可行。有没有秘密的方式我只想要原始的非HTMLed Tweet!
这甚至是可能的,如果不是最好的方式将HTML从字符串中删除,因为我需要的只是原始推文。

2 个答案:

答案 0 :(得分:1)

我认为每个title的{​​{1}}标记都是您需要的。

答案 1 :(得分:1)

this post中的 removeHtmlTags 模板可以实现您的目标。

<xsl:template name="removeHtmlTags">
    <xsl:param name="html"/>
    <xsl:choose>
        <xsl:when test="contains($html, '&lt;')">
            <xsl:value-of select="substring-before($html, '&lt;')"/>
            <!-- Recurse through HTML -->
            <xsl:call-template name="removeHtmlTags">
                <xsl:with-param name="html" select="substring-after($html, '&gt;')"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$html"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

您没有指定输出的外观。这是一个简单的示例,它在文本前面打印“ Description X。。”的每个RSS项描述元素。

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output indent="yes"  method="text"/>

    <xsl:template match="/">
  <xsl:apply-templates select="rss/channel/item/description"/>
    </xsl:template>

 <xsl:template match="description">
<!--This adds a label for each description: -->
Description <xsl:value-of select="position()"/>.)
  <xsl:call-template name="removeHtmlTags">
        <xsl:with-param name="html" select="." />
    </xsl:call-template>

 </xsl:template>

<xsl:template name="removeHtmlTags">
    <xsl:param name="html"/>
    <xsl:choose>
        <xsl:when test="contains($html, '&lt;')">
            <xsl:value-of select="substring-before($html, '&lt;')"/>
            <!-- Recurse through HTML -->
            <xsl:call-template name="removeHtmlTags">
                <xsl:with-param name="html" select="substring-after($html, '&gt;')"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$html"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

</xsl:stylesheet>

针对this RSS formatted search运行该样式表会产生以下输出:

Description 1.)
  Ke$ha desbanca Jay-Z e Lady Gaga na parada norte-americana   #adorei
Description 2.)
  STR8HIPHOP: VIDEO: Just Blaze Talks Baseline Records Studio &amp; His Work With Jay-Z:
    LTD Magazine talks to Just ... http://bit.ly/7y19WU
Description 3.)
  Nikon D3000 10MP $449.95 http://bit.ly/55gKZZ , DJ Hero Renegade Edition Featuring Jay-Z and Eminem $149 Amazon Now HURRY! http://bit.ly/5oW
Description 4.)
  #nowplaying Empire State Of Mind , jay-z and  alcia keys !
Description 5.)
  #NowPlaying R. Kelly - Fiesta Remix feat_ Jay-Z http://qstat.us/z6lp
Description 6.)
  50 Wants To Know Why Its Wrong For Beanie Sigel To Diss Jay-z But When The Game Disrespects Cu... http://tinyurl.com/yj5fma2
Description 7.)
  Nuove Foto: Mariah, Beyonce e Jay-Z, Monica! http://bit.ly/4Em2HL
Description 8.)
  NOW PLAYING: Jay-Z - Young Forever [Jay-Z + Mr Hudson] [Album Version] http://www.qmr.fm
Description 9.)
  Jay-Z tops News&apos; list of Hot New Yorkers in 2009 - http://shar.es/a91pQ
Description 10.)
  VIDEO: Just Blaze Talks Baseline Records Studio &amp; His Work With Jay-Z:
 LTD Magazine talks to Just Blaze about.. http://tinyurl.com/yzx3str
Description 11.)
  Download Cookin&apos; Soul Presents: Game &amp; Jay-Z – The RED Album | The …: Mash up posse producers Cookin&apos; Sou.. http://bit.ly/70rDNk
Description 12.)
  @Plex_Luthor you and Jay-Z! no way! lol The secret handshake ftw.
Description 13.)
  Questlove and Jay-Z make a bet on the World Series (The Fightins) http://o-x.fr/9yr7
Description 14.)
  Clip Jay-Z ft. Mr. Hudson - Young Forever: http://www.youtube.com/v/E1nbvplgElw http://bit.ly/4ze0If
Description 15.)
  musica nova → Jay-Z ft. Alicia Keys - Empire state of mind (New York) .. mto filé