user1009453
user1009453

Reputation: 707

Merge output when using "or" operator in xpath

I have an xpath expression which makes use of the "|"-operator to select several nodes/divs of an web page.

This is the expression:

hxs.select('//div[@class="cat"]/p|//div[@class="entry"]').extract()

But when I output the result I get a comma between the output of the first expression

//div[@class="cat"]/p

and the second

//div[@class="entry"]

Like:

'Lorem ipsum', 'Ipsum Lorem'

Is there a way to get rid of the comma?

Like:

'Lorem ipsum Ipsum lorem'

Or is there perhaps a better way to write xpath expressions which selects Both THIS div AND THIS div.

The rest of the application is written in Python, but I don't think this is relevant to the question. Any help much appreciated!

Upvotes: 1

Views: 501

Answers (1)

Alexander
Alexander

Reputation: 23537

Use join().

" ".join(hxs.select('//div[@class="cat"]/p|//div[@class="entry"]').extract())

Upvotes: 1

Related Questions