Issue
I need to write a selector in Python Scrapy.
I want to get % of CBD and % of THC.
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?
Solution
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()
Answered By - gangabass
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.