2013-03-15 1 views
0

я пытаюсь написать XPath, который будет выбирать <h3>, <ul> and <p> теги под div[@class="content"] но с p[position() > 1 and position() < last() - 1]Извлечение текста образуют специфические вложенные узлы с атрибутами

До сих пор я это ....

//div[@class="content"]/*[self::h3 or self::ul or self::p[position() > 1 and position() < last() - 1]]//text() 

Но это Безразлично Не работай.

Вот HTML: https://gist.github.com/umrashrf/5167711

+0

Я работаю в «firebug + firepath». Вы попробовали 'import lxml.html' – kev

ответ

0

ОК ваш XML не был хорошо образован, так что я установил это первое.

<?xml version="1.0" encoding="UTF-8"?> 
<div class="content"> 
<h1/> 
<h2> 
    <p>Certified Nursing Assistant - Full Time</p> 
Job Summary</h2> 
<p>Responsible for providing personal care and assistance for residents in long  
term care facility.</p> 
<h2> 
</h2> 
<h3>Essential Functions:</h3> 
<ul> 
    <li> 
     <span style="line-height: 1.5;">Responsible</span> for providing 
personal care and assistance to residents </li> 
    <li>Assist residents in and out of bed, dressing, feeding, grooming and 
personal hygiene. </li> 
    <li>Provide basic treatments as required and directed by nursing staff. 
</li> 
    <li>Responsible for observing and reporting changes in residents' physical 
and emotional conditions to charge nurse. </li> 
</ul> 
<h3>Qualifications: </h3> 
<p>Education:</p> 
<ul> 
    <li>High school diploma or equivalent </li> 
    <li>Successful completion of state approved certified nursing assistance 
course </li> 
</ul> 
<p>Experience:</p> 
<ul> 
    <li>Previous health care related experience preferred </li> 
</ul> 
<a id="ctl00_ctl01_namelink" class="btn" href="employment-application.aspx? 
positionid=34">Apply Online</a> 
<br/> 
<br/> 
<h2> 
Apply in Person</h2> 
<p> 
To apply in persion please stop by Shenandoah Medical Center to pick up a job 
application.</p> 
<h2> 
Apply by Mail</h2> 
<p> 
To apply by mail, download and print <a target="_blank" href="/filesimages/Careers/SMC 
Employment Application.pdf"> 
    this form</a>. Please fill out the application and then mail to:<br/> 
    <br/> 
    <strong>Shenandoah Medical Center, Human Resources<br/> 
    </strong>300 Pershing Avenue<br/> 
Shenandoah, IA 51601</p> 
</div> 

Теперь, если я правильно понимаю ваш вопрос, вы хотите найти все h3, ул и р теги, которые являются дочерними узлами ДИВ [@ класс = «содержание»] и каждый выбранный узел ребенок должен удовлетворять состояние [положение()> 1 и позиция() < последний() - 1]. Для этого я думаю, что этот единственный XPATH будет делать:

//div[@class="content"]/h3[position() > 1 and position() < last() - 1] |   
//div[@class="content"]/p[position() > 1 and position() < last() - 1] | 
//div[@class="content"]/ul[position() > 1 and position() < last() - 1] 
Смежные вопросы