xpath works for just one item when add // in it
Question: I have this html page

    
    
    <page>
    <div class="results-list">
    
        <div class="item paid-featured-item"></div>
        <div class="item paid-featured-item"></div>
        <div class="item paid-featured-item"></div>
        <div class="item paid-featured-item"></div>
        <div class="item paid-featured-item"></div>
        <div class="item paid-featured-item"></div>
        <div class="item paid-featured-item"></div>
        <div class="item paid-featured-item"></div>
    
    </div>
    </page>
    

and Inside each "item paid-featured-item", I have this:

    
    
    <div class="item paid-featured-item">
        <div class="somethign">
            <div class="title">
                This is the title
            </div>
        </div>
        <div class="anotherthing">
        </div>
    </div>
    

I want to extract the title using xpath.

### what I have tried

    
    
    Container = "//div[@class='results-list']"
    
    for item in Container:
        title = "//div[@class='title']/text()"
    

I get 8 titles but each one is the title of the first item.

### i am sure that is because i used //

what should I do please?

### first

I don't want to use css selectors because it is not allowed in my work

### second

I don't want to use `class="something"` because this div not always exist in
my page.

### third

i am using scrapy with python

### fourth

appreciate your help


Answer: Say your page looks like (`page.html`):

    
    
    <page>
      <div id="results-list">
        <div class="item paid-featured-item">
          <div class="something">
            <div class="title">Title 1</div>
          </div>
          <div class="anotherthing"></div>
        </div>
        <div class="item paid-featured-item">
          <div class="something">
            <div class="title">Title 2</div>
          </div>
          <div class="anotherthing"></div>
        </div>
        <div class="item paid-featured-item">
          <div class="something">
            <div class="title">Title 3</div>
          </div>
          <div class="anotherthing"></div>
        </div>
        <div class="item paid-featured-item">
          <div class="something">
            <div class="title">Title 4</div>
          </div>
          <div class="anotherthing"></div>
        </div>
      </div>
    </page>
    

To extract each title, you do:

    
    
    from scrapy.selector import Selector
    sel = Selector(text=open('page.html').read())
    
    container = sel.xpath('//div[@id="results-list"]')
    items = container.xpath('.//div[@class="item paid-featured-item"]')
    for item in items:
        # *extracted* is a single-item list containing the title.
        extracted = item.xpath('.//div[@class="title"]/text()').extract()
        title = extracted[0]
        print title
    

This will output:

    
    
    Title 1
    Title 2
    Title 3
    Title 4
    

