我能用正则表达式提取标题吗?

2024-06-11 00:31:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个问题,提取标题,因为我设法提取 但是 它不是只针对“标题”的,它提取了其他内容作为 好 我怎样才能做一个正则表达式呢

我试过用(?)>;)([^&燃气轮机<;]+?)(?=标签也是

    <rss xmlns:dc="http://purl.org/dc/elements/1.1/" 

    xmlns:media="http://search.yahoo.com/mrss/" 
    xmlns:atom="http://www.w3.org/2005/Atom" 
    xmlns:nyt="http://www.nytimes.com/namespaces/rss/2.0" version="2.0">
    <script/>
    <channel>
    <title>NYT > Top Stories</title>
    <link>https://www.nytimes.com?emc=rss&partner=rss</link>
    <atom:link 
  href="https://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml" 
     rel="self" type="application/rss+xml"/>
    <description/>
    <language>en-us</language>
    <copyright>Copyright 2019 The New York Times Company</copyright>
    <lastBuildDate>Thu, 17 Oct 2019 22:53:19 +0000</lastBuildDate>
    <image>
    <title>NYT > Top Stories</title>
    <url>
    https://static01.nyt.com/images/misc/NYT_logo_rss_250x40.png
    </url>
    <link>https://www.nytimes.com?emc=rss&partner=rss</link>
    </image>
    <item>
    <title>
    Mulvaney Says Trump Held Back Ukraine Aid Pending Investigation of 
     Democrats
    </title>
    <link>
    https://www.nytimes.com/2019/10/17/us/politics/mick-mulvaney-trump- 
     ukraine.html?emc=rss&partner=rss
    </link>
    <guid isPermaLink="true">
    https://www.nytimes.com/2019/10/17/us/politics/mick-mulvaney-trump- 
     ukraine.html
    </guid>
    <atom:link href="https://www.nytimes.com/2019/10/17/us/politics/mick- 
     mulvaney-trump-ukraine.html?emc=rss&partner=rss" rel="standout"/>
    <description>
    Undercutting President Trump’s denial of a quid pro quo, the acting 
    White House chief of staff told reporters that military aid was held 
      back in part to prod Ukraine to investigate Democrats.
    </description>
    <dc:creator>Michael D. Shear</dc:creator>

    I

我提取所有以标题结尾的内容以及如何制作 specific that I want to extract the below mentioned part only and not the other content

     <item>
    <title>
    Mulvaney Says Trump Held Back Ukraine Aid Pending Investigation of 
     Democrats
    </title>

我有可能拿到这个头衔,如果有人能帮我,那将是一个巨大的帮助,我已经挣扎了好几天了


Tags: ofhttpscomhttp标题partnertitlewww