Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python从文本中删除wordpress标题短代码_Python_Wordpress - Fatal编程技术网

使用python从文本中删除wordpress标题短代码

使用python从文本中删除wordpress标题短代码,python,wordpress,Python,Wordpress,您好,我正在将wordpress博客导出到另一个CMS,在上传到新平台之前,我需要从html中删除开始和结束[caption]标记及其内容,而不删除其中包含的标记。代码的其余部分在这里供参考 理想情况下,我希望实现如下功能: def strip_caption_tags(content): no_captions = do_some_stuff_presumably_regex(content) return caption 这是一个数据示例: <![CDATA[[caption

您好,我正在将wordpress博客导出到另一个CMS,在上传到新平台之前,我需要从html中删除开始和结束[caption]标记及其内容,而不删除其中包含的标记。代码的其余部分在这里供参考

理想情况下,我希望实现如下功能:

def strip_caption_tags(content):
  no_captions = do_some_stuff_presumably_regex(content)
  return caption
这是一个数据示例:

<![CDATA[[caption id="attachment_5582" align="alignleft" width="1024" caption="Out on Lake Burley Griffin with members of the Canberra Ice Dragons Paddle Club, January 2014"]<a href="http://www.andrewleigh.com/blog/wp-content/uploads/2014/01/ACT-Dragon-Boat-3.jpg"><img class="size-large wp-image-5582" title="ACT Dragon Boat 3" src="http://www.andrewleigh.com/blog/wp-content/uploads/2014/01/ACT-Dragon-Boat-3-1024x682.jpg" alt="" width="1024" height="682" /></a>[/caption]

<div class="mceTemp"><strong>Ca</strong><strong>l</strong><span style="font-weight: bold;">l for Local Sporting Champions to step up and apply for grants on offer</span></div>
Young people can find it difficult to meet the ongoing and significant costs associated with participation at sporting competitions.

The Local Sporting Champions program is designed to provide financial assistance for young people towards the cost of travel, accommodation, uniforms or equipment when competing, coaching or officiating at an official sports event.

For more information on the Local Sporting Champions program visit the Australian Sports Commission website: <a href="http://www.ausport.gov.au/champions">www.ausport.gov.au/champions</a>.]]>
Call让当地体育冠军站出来申请提供的补助金
年轻人会发现很难满足与参加体育比赛相关的持续和重大成本。
当地体育冠军计划旨在为年轻人提供经济援助,以支付在正式体育赛事中进行比赛、指导或主持时的旅行、住宿、制服或设备费用。
有关本地体育冠军计划的更多信息,请访问澳大利亚体育委员会网站:。]]>

这是对您的问题的回答,但我不能100%确定您是否提出了有关转换数据的正确问题。在将数据库导出为XML之前,这可能更容易处理,但是如果您想用python中的正则表达式替换内容:

import re
contents = //... get your post contents here
contents = re.sub(r'\[/?caption[^\]]*?\]', '', contents)
对于正则表达式:

  • \[
    匹配文本左方括号
    [
  • /?
    可以选择匹配正斜杠
    /
  • caption
    匹配
    caption
  • [^\]*?
    非右方括号字符的延迟匹配
    ]
  • \]
    匹配文本右方括号
这将同时匹配
[caption foo=“bar”]
[/caption]

使用您的示例查看它的实际操作,并附带其他说明