0
我有一些HTML:將HTML從定義的起點解析到定義的終點?
<hr noshade>
<p><a href="#1">Some text here</a></p>
<p style="margin-top:0pt;margin-bottom:0pt;line-height:120%;"><span style="color:#000000;font-weight:bold;">This is some description</span></p>
<hr noshade> <!-- so <hr noshade> is the delimiter for me -->
<p><a href="#2">Some more text here</a></p>
<p style="margin-top:0pt;margin-bottom:0pt;line-height:120%;"><span style="color:#000000;font-weight:bold;">This is description for some more text</span></p>
<hr noshade>
在使用引入nokogiri分析,我想每個組的標籤是由我自己的分隔符<hr noshade>
分離之間打印信息。因此,第一個塊應在兩個hr noshade
標籤之間的所有「p」標籤之間打印信息等等。
感謝您的回覆。是的,這對我來說很有意義。我現在試圖想象一個更通用的解決方案,因爲html文件是由軟件自動生成的,所以我不知道它可能生成的
的數量。 –
所以,我試過這個: path ='// hr [1] [@ noshade]/following-sibling :: * [not(self :: hr [@noshade])] [count(preceding-sibling :: '['noshade])= 1]' xpath = doc.xpath(路徑) 但是我得到一個錯誤,因爲,「等於」(Nokogiri :: CSS :: SyntaxError)後的「unexpected」]'「 –
CSS :: SyntaxError錯誤?我沒有使用Nokogiri進行測試,只能用Python的'lxml.html' –