Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.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 我可以用正则表达式提取标题吗?_Python_Html - Fatal编程技术网

Python 我可以用正则表达式提取标题吗?

Python 我可以用正则表达式提取标题吗?,python,html,Python,Html,我在提取标题时遇到问题,因为我设法提取了标题 但是 它并不是只针对“标题”的,它还提取了其他内容 好 我怎样才能做一个正则表达式呢 我尝试使用(?!>)([^>使用xml解析器,如标准库中的,或特别是rss中的。和之间有多个标题,是否还有其他方法可以帮助将其缩小到您想要的确切标题?\n\n[A-Za-z].*\n所以我使用了这个,它选择了所有,但我只想要两个标题标记中的内容使用xml解析器,例如标准库中的,或者,或者专门用于rss。在和之间有多个标题,是否还有其他方法可以帮助将其缩小到您想要的确

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


我尝试使用(?!>)([^>使用xml解析器,如标准库中的,或特别是rss中的。和之间有多个标题,是否还有其他方法可以帮助将其缩小到您想要的确切标题?\n\n[A-Za-z].*\n所以我使用了这个,它选择了所有,但我只想要两个标题标记中的内容使用xml解析器,例如标准库中的,或者,或者专门用于rss。在和之间有多个标题,是否还有其他方法可以帮助将其缩小到您想要的确切标题?\n\n[A-Za-z].*\n所以我使用了这个,它选择了所有内容,但我只想将内容放在两个标题标记中
    <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
     <item>
    <title>
    Mulvaney Says Trump Held Back Ukraine Aid Pending Investigation of 
     Democrats
    </title>