Ruby 别害怕。你害怕我们。你害怕改变。我不知道未来。我不是来告诉你这将如何结束的。我来这里是想告诉你事情将如何开始。我要挂断电话,然后给这些人看你不想让他们看到的东西。我要向他们展示一个没有你的世界。一个没有规则和控制、没有边界或边界的世界;一个一切皆有可能的世界。我们从哪里出发,我留给你一个选择 哇 我懂功夫 嗯。嗯,听起来是个不错的交易。但我想我可能有一个更好的。怎么样,我给你手指[他有],你给我打电话 枪。。很多枪 没有勺子 我的名字…是尼奥

Ruby 别害怕。你害怕我们。你害怕改变。我不知道未来。我不是来告诉你这将如何结束的。我来这里是想告诉你事情将如何开始。我要挂断电话,然后给这些人看你不想让他们看到的东西。我要向他们展示一个没有你的世界。一个没有规则和控制、没有边界或边界的世界;一个一切皆有可能的世界。我们从哪里出发,我留给你一个选择 哇 我懂功夫 嗯。嗯,听起来是个不错的交易。但我想我可能有一个更好的。怎么样,我给你手指[他有],你给我打电话 枪。。很多枪 没有勺子 我的名字…是尼奥,ruby,xpath,nokogiri,xpath-2.0,wikimedia,Ruby,Xpath,Nokogiri,Xpath 2.0,Wikimedia,使用API将使解析变得更容易。下面是一个查询,它将引出第一个部分: 输出: <?xml version="1.0"?> <api> <parse title="The Matrix"> <wikitext xml:space="preserve">== Neo == [[File:The.Matrix.glmatrix.2.png|thumb|right|Unfortunately, no one can be ''told'' wh

使用API将使解析变得更容易。下面是一个查询,它将引出第一个部分:

输出:

<?xml version="1.0"?>
<api>
  <parse title="The Matrix">
    <wikitext xml:space="preserve">== Neo ==
[[File:The.Matrix.glmatrix.2.png|thumb|right|Unfortunately, no one can be ''told'' what The Matrix is. You have to see it for yourself.]]
[[Image:Arty spoon.jpg|thumb|right|Do not try to bend the spoon — that's impossible. Instead, only try to realize the truth: there is no spoon.]]

* I know you're out there. I can feel you now. I know that you're afraid. You're afraid of us. You're afraid of change. I don't know the future. I didn't come here to tell you how this is going to end. I came here to tell you how it's going to begin. I'm going to hang up this phone, and then I'm going to show these people what you don't want them to see. I'm going to show them a world … without you. A world without rules and controls, without borders or boundaries; a world where anything is possible. Where we go from there is a choice I leave to you.

* Whoa.
* I know kung-fu.

* Yeah. Well, that sounds like a pretty good deal. But I think I may have a better one. How about, I give you the finger [He does] and you give me my phone call.

* Guns.. lots of guns...

* There is no spoon. 

* My name...is Neo!</wikitext>
  </parse>
</api>
["I know you're out there. I can feel you now. I know that you're afraid. You're afraid of us. You're afraid of change. I don't know the future. I didn't come here to tell you how this is going to end. I came here to tell you how it's going to begin. I'm going to hang up this phone, and then I'm going to show these people what you don't want them to see. I'm going to show them a world … without you. A world without rules and controls, without borders or boundaries; a world where anything is possible. Where we go from there is a choice I leave to you.",
 "Whoa.",
 "I know kung-fu.",
 "Yeah. Well, that sounds like a pretty good deal. But I think I may have a better one. How about, I give you the finger [He does] and you give me my phone call.",
 "Guns.. lots of guns...",
 "There is no spoon. ",
 "My name...is Neo!"]
用法:

Wikiquote.get_quotes("The_Matrix")
输出:

<?xml version="1.0"?>
<api>
  <parse title="The Matrix">
    <wikitext xml:space="preserve">== Neo ==
[[File:The.Matrix.glmatrix.2.png|thumb|right|Unfortunately, no one can be ''told'' what The Matrix is. You have to see it for yourself.]]
[[Image:Arty spoon.jpg|thumb|right|Do not try to bend the spoon — that's impossible. Instead, only try to realize the truth: there is no spoon.]]

* I know you're out there. I can feel you now. I know that you're afraid. You're afraid of us. You're afraid of change. I don't know the future. I didn't come here to tell you how this is going to end. I came here to tell you how it's going to begin. I'm going to hang up this phone, and then I'm going to show these people what you don't want them to see. I'm going to show them a world … without you. A world without rules and controls, without borders or boundaries; a world where anything is possible. Where we go from there is a choice I leave to you.

* Whoa.
* I know kung-fu.

* Yeah. Well, that sounds like a pretty good deal. But I think I may have a better one. How about, I give you the finger [He does] and you give me my phone call.

* Guns.. lots of guns...

* There is no spoon. 

* My name...is Neo!</wikitext>
  </parse>
</api>
["I know you're out there. I can feel you now. I know that you're afraid. You're afraid of us. You're afraid of change. I don't know the future. I didn't come here to tell you how this is going to end. I came here to tell you how it's going to begin. I'm going to hang up this phone, and then I'm going to show these people what you don't want them to see. I'm going to show them a world … without you. A world without rules and controls, without borders or boundaries; a world where anything is possible. Where we go from there is a choice I leave to you.",
 "Whoa.",
 "I know kung-fu.",
 "Yeah. Well, that sounds like a pretty good deal. But I think I may have a better one. How about, I give you the finger [He does] and you give me my phone call.",
 "Guns.. lots of guns...",
 "There is no spoon. ",
 "My name...is Neo!"]

使用API将使解析变得更容易。下面是一个查询,它将引出第一个部分:

输出:

<?xml version="1.0"?>
<api>
  <parse title="The Matrix">
    <wikitext xml:space="preserve">== Neo ==
[[File:The.Matrix.glmatrix.2.png|thumb|right|Unfortunately, no one can be ''told'' what The Matrix is. You have to see it for yourself.]]
[[Image:Arty spoon.jpg|thumb|right|Do not try to bend the spoon — that's impossible. Instead, only try to realize the truth: there is no spoon.]]

* I know you're out there. I can feel you now. I know that you're afraid. You're afraid of us. You're afraid of change. I don't know the future. I didn't come here to tell you how this is going to end. I came here to tell you how it's going to begin. I'm going to hang up this phone, and then I'm going to show these people what you don't want them to see. I'm going to show them a world … without you. A world without rules and controls, without borders or boundaries; a world where anything is possible. Where we go from there is a choice I leave to you.

* Whoa.
* I know kung-fu.

* Yeah. Well, that sounds like a pretty good deal. But I think I may have a better one. How about, I give you the finger [He does] and you give me my phone call.

* Guns.. lots of guns...

* There is no spoon. 

* My name...is Neo!</wikitext>
  </parse>
</api>
["I know you're out there. I can feel you now. I know that you're afraid. You're afraid of us. You're afraid of change. I don't know the future. I didn't come here to tell you how this is going to end. I came here to tell you how it's going to begin. I'm going to hang up this phone, and then I'm going to show these people what you don't want them to see. I'm going to show them a world … without you. A world without rules and controls, without borders or boundaries; a world where anything is possible. Where we go from there is a choice I leave to you.",
 "Whoa.",
 "I know kung-fu.",
 "Yeah. Well, that sounds like a pretty good deal. But I think I may have a better one. How about, I give you the finger [He does] and you give me my phone call.",
 "Guns.. lots of guns...",
 "There is no spoon. ",
 "My name...is Neo!"]
用法:

Wikiquote.get_quotes("The_Matrix")
输出:

<?xml version="1.0"?>
<api>
  <parse title="The Matrix">
    <wikitext xml:space="preserve">== Neo ==
[[File:The.Matrix.glmatrix.2.png|thumb|right|Unfortunately, no one can be ''told'' what The Matrix is. You have to see it for yourself.]]
[[Image:Arty spoon.jpg|thumb|right|Do not try to bend the spoon — that's impossible. Instead, only try to realize the truth: there is no spoon.]]

* I know you're out there. I can feel you now. I know that you're afraid. You're afraid of us. You're afraid of change. I don't know the future. I didn't come here to tell you how this is going to end. I came here to tell you how it's going to begin. I'm going to hang up this phone, and then I'm going to show these people what you don't want them to see. I'm going to show them a world … without you. A world without rules and controls, without borders or boundaries; a world where anything is possible. Where we go from there is a choice I leave to you.

* Whoa.
* I know kung-fu.

* Yeah. Well, that sounds like a pretty good deal. But I think I may have a better one. How about, I give you the finger [He does] and you give me my phone call.

* Guns.. lots of guns...

* There is no spoon. 

* My name...is Neo!</wikitext>
  </parse>
</api>
["I know you're out there. I can feel you now. I know that you're afraid. You're afraid of us. You're afraid of change. I don't know the future. I didn't come here to tell you how this is going to end. I came here to tell you how it's going to begin. I'm going to hang up this phone, and then I'm going to show these people what you don't want them to see. I'm going to show them a world … without you. A world without rules and controls, without borders or boundaries; a world where anything is possible. Where we go from there is a choice I leave to you.",
 "Whoa.",
 "I know kung-fu.",
 "Yeah. Well, that sounds like a pretty good deal. But I think I may have a better one. How about, I give you the finger [He does] and you give me my phone call.",
 "Guns.. lots of guns...",
 "There is no spoon. ",
 "My name...is Neo!"]

好的,但我使用“矩阵”页面只是作为一个例子。它应该也适用于其他页面。(无论如何,我得到了一个“语法错误”)好的,但我使用“矩阵”页面只是作为一个例子。它应该也适用于其他页面。(无论如何,我得到一个“语法错误”)可能重复@Phrogz对我来说,问题是我不知道第一节和第二节的名称。我不知道,即使有第二部分,你为什么不使用?它以XML形式返回信息,允许您在不解析HTML的情况下检索信息,因为这是同一件事。API只返回页面的HTML,而不是结构化数据。@DimitreNovatchev在接下来的几天里,我会抽出时间测试它,我会接受你的答案。现在有点忙;)@Phrogz的可能重复对我来说,问题是我不知道第一节和第二节的名称。我不知道,即使有第二部分,你为什么不使用?它以XML形式返回信息,允许您在不解析HTML的情况下检索信息,因为这是同一件事。API只返回页面的HTML,而不是结构化数据。@DimitreNovatchev在接下来的几天里,我会抽出时间测试它,我会接受你的答案。现在有点忙;)“矩阵”页面只是一个例子@id=“Neo”不是通用的。不幸的是,我没有这个名字。怎么可能更通用呢?。我知道的是:“wikiquote页面的第一部分”@user1028100,请参见我的更新答案——新的解决方案动态地确定第一部分的
id
。“矩阵”页面只是一个示例@id=“Neo”不是通用的。不幸的是,我没有这个名字。怎么可能更通用呢?。我知道的是:“wikiquote页面的第一部分”@user1028100,请参见我的更新答案——新的解决方案动态地确定第一部分的
id
  substring(//div[h2='Contents']
              /following-sibling::ul[1]
                 /li[1]/a/@href,
            2)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:variable name="vSectionId" select=
 "substring(//div[h2='Contents']
                      /following-sibling::ul[1]
                         /li[1]/a/@href,
                    2)
 "/>

 <xsl:template match="/">
  <xsl:copy-of select=
   "(//h2[span/@id=$vSectionId])[1]
                /following-sibling::ul
      [count(.
            |
             (//h2[span/@id=$vSectionId])[1]
                /following-sibling::h2[1]
                  /preceding-sibling::ul
             )
      =
       count((//h2[span/@id=$vSectionId])[1]
                /following-sibling::h2[1]
                  /preceding-sibling::ul
             )
      ]
        /li

   "/>
 </xsl:template>
</xsl:stylesheet>
<li>I know you're out there. I can feel you now. I know that you're afraid. You're afraid of us. You're afraid of change. I don't know the future. I didn't come here to tell you how this is going to end. I came here to tell you how it's going to begin. I'm going to hang up this phone, and then I'm going to show these people what you don't want them to see. I'm going to show them a world … without you. A world without rules and controls, without borders or boundaries; a world where anything is possible. Where we go from there is a choice I leave to you.</li>
<li>Whoa.</li>
<li>I know kung-fu.</li>
<li>Yeah. Well, that sounds like a pretty good deal. But I think I may have a better one. How about, I give you the finger [He does] and you give me my phone call.</li>
<li>Guns.. lots of guns...</li>
<li>There is no spoon.</li>
<li>My name...is Neo!</li>
<?xml version="1.0"?>
<api>
  <parse title="The Matrix">
    <wikitext xml:space="preserve">== Neo ==
[[File:The.Matrix.glmatrix.2.png|thumb|right|Unfortunately, no one can be ''told'' what The Matrix is. You have to see it for yourself.]]
[[Image:Arty spoon.jpg|thumb|right|Do not try to bend the spoon — that's impossible. Instead, only try to realize the truth: there is no spoon.]]

* I know you're out there. I can feel you now. I know that you're afraid. You're afraid of us. You're afraid of change. I don't know the future. I didn't come here to tell you how this is going to end. I came here to tell you how it's going to begin. I'm going to hang up this phone, and then I'm going to show these people what you don't want them to see. I'm going to show them a world … without you. A world without rules and controls, without borders or boundaries; a world where anything is possible. Where we go from there is a choice I leave to you.

* Whoa.
* I know kung-fu.

* Yeah. Well, that sounds like a pretty good deal. But I think I may have a better one. How about, I give you the finger [He does] and you give me my phone call.

* Guns.. lots of guns...

* There is no spoon. 

* My name...is Neo!</wikitext>
  </parse>
</api>
require 'httparty'

class Wikiquote
  include HTTParty
  base_uri 'en.wikiquote.org/w/'

  def self.get_quotes(page)
    url = "/api.php?action=parse&page=#{page}&section=1&prop=wikitext&format=xml"
    headers = {"User-Agent" => "Wikiquote scraper 1.0"}
    content = get(url, headers: headers)['api']['parse']['wikitext']['__content__']
    return content.scan(/^\* (.*)$/).flatten
  end
end
Wikiquote.get_quotes("The_Matrix")
["I know you're out there. I can feel you now. I know that you're afraid. You're afraid of us. You're afraid of change. I don't know the future. I didn't come here to tell you how this is going to end. I came here to tell you how it's going to begin. I'm going to hang up this phone, and then I'm going to show these people what you don't want them to see. I'm going to show them a world … without you. A world without rules and controls, without borders or boundaries; a world where anything is possible. Where we go from there is a choice I leave to you.",
 "Whoa.",
 "I know kung-fu.",
 "Yeah. Well, that sounds like a pretty good deal. But I think I may have a better one. How about, I give you the finger [He does] and you give me my phone call.",
 "Guns.. lots of guns...",
 "There is no spoon. ",
 "My name...is Neo!"]