Note that there are some explanatory texts on larger screens.

plurals
  1. POXPath - Select text() in between two DIV identified by matching text in it
    primarykey
    data
    text
    <p>I have this HTML,</p> <pre><code>&lt;div id="General" class="detailOn"&gt; &lt;div class="tabconstraint"&gt;&lt;/div&gt; &lt;div id="InstitutionMain" class="detailseparate"&gt; &lt;div id="InstitutionMain_divINFORight" style="float:right;width:40%"&gt;&lt;/div&gt; &lt;div style="font-weight:bold;padding-top:6px"&gt;Special Learning Opportunities&lt;/div&gt; Distance learning opportunities&lt;br&gt; &lt;div style="font-weight:bold;padding-top:6px"&gt;Student Services&lt;/div&gt; Remedial services&lt;br&gt; Academic/career counseling service&lt;br&gt; &lt;div style="font-weight:bold;padding-top:6px"&gt;Credit Accepted&lt;/div&gt; Dual credit&lt;br&gt; Credit for life experiences&lt;br&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>I want to extract</p> <pre><code>text() = between [Div/text() = "Special Learning Opportunities&lt;/div&gt; Distance learning opportunities"] and [div/text()="Student Services"] </code></pre> <p>similarly for other divs</p> <p>I tried this code which gives me all text following the identified div,</p> <pre><code>div[1]/div[contains(text(),"Special Learning Opportunities")]/following-sibling::text() </code></pre> <p>While this code gives me the all text before the div</p> <pre><code>div[1]/div[contains(text(),"Student Services")]/preceding-sibling::text() </code></pre> <p>Is there a way to get exactly all the text in between specified DIVs. Thanks in advance. </p> <p>I am using python 2.x and scrapy for crawling.</p> <p>Note: My current method:- using these three xpaths</p> <pre><code>item['SLO']=site.select('div[1]/div[contains(text(),"Special Learning Opportunities")]/following-sibling::text()').extract() item['SS']=site.select('div[1]/div[contains(text(),"Student Services")]/following-sibling::text()').extract() item['CA']=site.select('div[1]/div[contains(text(),"Credit Accepted")]/following-sibling::text()').extract() </code></pre> <p>I get three items like this,</p> <pre><code>item['SLO']=['Distance learning opportunities','Remedial services',' Academic/career counseling service','Dual credit','Credit for life experiences'] item['SS']=['Remedial services',' Academic/career counseling service','Dual credit','Credit for life experiences'] item['CA']=['Dual credit','Credit for life experiences'] </code></pre> <p>and then I work on python list to get what i want,</p> <p>But I think there should be q quicker way in XPath to do so.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload