Random 102
Random 102

Reputation: 147

Get div with certain attribute - Scrapy selector

I have HTML that looks like:

<div class="row">
  <div class="col-md-6">
    <dl>
      <dt>Prerequisites</dt>
      <dd>15-510</dd>
    </dl>
  </div>
  <div class="col-md-6">
    <dl>
      <dt>Corequisites</dt>
      <dd>None</dd>
    </dl>
  </div>
</div>

And I want to get the value inside <dd> based on the corresponding <dt>. For example, I want to do something like select 'Prerequisites' and get '15-510'.

Thank you.

Upvotes: 0

Views: 212

Answers (1)

GHajba
GHajba

Reputation: 3691

How about xpath("//dt[text() = 'Prerequisites']/following-sibling::dd")?

Upvotes: 1

Related Questions