I am working with Python and Selenium, using an xpath class selector I am currently able to locate a specific div that contains text I wish to record.
The problem is this div can be void of any information (which I currently handle) or contain between 1-3 spans worth of text that I cannot access. What I am trying to do is pull all text, including the text within the spans.
Example HTML:
<div class="desktop-product-list-item__PotencyInfo-sc-8wto4u-14 hdncuE">
<span class="grey-caps-text-sc-91lz0n-0 huWIpn">TAC</span>
28.3% |
<span class="grey-caps-text-sc-91lz0n-0 huWIpn">THC:</span>
26.2%
</div>
Current XPATH:
potencyList = response1.xpath('//div[contains(@class, "__PotencyInfo-sc-")]/text()').getall()
With my current xpath I only pull the numbers "26.2" and "28.3", as the "TAC:" text and the "THC:" text are within spans. My goal is to pull all text, in order and then manipulate further with regex as needed.
I believe I could target the spans directly, but am unsure how I would do so when I take into account their varied quantities.
Also should note I am using Chromedriver.
Any insight would be greatly appreciated.