ericlee
ericlee

Reputation: 2753

xpath retrieving text inclusive of tag

I trying to parse a webpage and get all the content inside a div tag named div1. I tried ('div[@class="div1"]') which gives me the content below

  <div class="div1">
                  <p>
                    something something <br>
                    abc<br>
                    def
                  </p>
              </div>

However, I am trying to get everything that is inside the div tag, not including the div tag as shown below

    <p>
                something something <br>
                abc<br>
                def
              </p>

Upvotes: 0

Views: 46

Answers (2)

fm0
fm0

Reputation: 141

Try changing your xpath to

div[@class="div1"]/child::*

Quote from https://www.w3.org/TR/xpath/#location-paths:

child::* selects all element children of the context node

Upvotes: 1

Bill Hileman
Bill Hileman

Reputation: 2836

For one thing, you're looking for @id when it's @class

Upvotes: 0

Related Questions