C ++ Builder AnsiString删除除&之外的所有内容...>

时间:2014-10-25 13:08:56

标签: c++ c++builder-xe2 c++builder-6 c++builder-xe c++builder-xe5

我有:Memo2->Text= IdHTTP1->Get("http://www.twitch.tv/starladder1");

在Memo2中:

`<!DOCTYPE html>
<html lang='en' style='overflow: hidden;' xml:lang='en' xmlns:fb='http://www.facebook.com/2008/fbml' xmlns:og='http://opengraphprotocol.org/schema/' xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>Twitch</title>
<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'>
<meta content='app-id=460177396, app-argument=twitch://open' name='apple-itunes-app'>
<meta content='Twitch' name='description'>
<link href='/favicon.ico' rel='shortcut icon' type='image/x-icon'>
<meta content='general' name='rating'>
<meta content='NIH9y45AePyUB62Ur2myinvJOvH77ufgjd6wKiQB6sA' name='google-site-verification'>
<a href='https://plus.google.com/115463106831870703431' rel='publisher'></a>
<meta content='Twitch' property='og:site_name'>
<meta content='161273083968709' property='fb:app_id'>
<meta content='streamname' property='og:title'>
<meta content='STREAM NAME STREAM NAME' property='og:description'>
<meta content='http://static-cdn.jtvnw.net/jtv_user_pictures/starladder1-profile_image-557367f831a49ebb-600x600.png' property='og:image'>
<meta property='og:url'>
<meta content='video.other' property='og:type'>
<meta content='http://www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf?channel=starladder1&playerType=facebook' property='og:video'>
<meta content='https://www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf?channel=starladder1&playerType=facebook' property='og:video:secure_url'>
<meta content='application/x-shockwave-flash' property='og:video:type'>
<meta content='378' property='og:video:height'>
<meta content='620' property='og:video:width'>`

如何删除所有exept'STREAM NAME STREAM NAME'。我需要Label1-&gt; Caption ='STREAM NAME STREAM NAME'。

1 个答案:

答案 0 :(得分:1)

有问题的网站正在使用与XML兼容的XHTML,因此您可以使用任何XML解析器来提取值,例如Embarcadero的TXMLDocument组件或任意数量的第三方解析器(我更喜欢{{3}我自己)。您对content属性为meta的{​​{1}}元素的property属性感兴趣。解析XHTML后,您可以手动遍历查看og:description属性的元素,直到找到所需的元素,或者您可以使用XPath查询来查找特定元素,例如:property

更新:有问题的网站使用格式错误的 XHTML,因此XML解析器无法正确处理它。因此,要么找到第三方HTML / XHTML解析器,要么手动执行简单的子串搜索,例如:

/html/head/meta[@property='og:description']