1

I need to write a selector in Python Scrapy.

I want to get % of CBD and % of THC.

CSS

test = productResponse
    .css('.woocommerce-product-details__short-description > p')[1]
    .get()

When I trying to do something like this i get result:

<p>
    <strong>CBD:</strong> 7.5%<br>
    <strong>THC:</strong><0.2%<br>
    <strong>Waga:</strong> 1 gram
</p>

But when I add the ::text I get only the value of CBD:

test = productResponse
    .css('.woocommerce-product-details__short-description > p::TEXT')[1]
    .get()

Result:

7.5%

How can I get value from Strong and second text value?

2

1 Answer 1

2

You don't need classes here. I strongly recommend switching to XPath:

cbd = response.xpath('//strong[.="CBD:"]/following-sibling::text()[1]').get()
thc = response.xpath('//strong[.="THC:"]/following-sibling::text()[1]').get()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.