#Illustration A
<span class="levelone">
<span class="leveltwo" dir="auto">
::before
"Blue"
::after
</span>
</span>
#Illustration B
<div class="itemlist">
<div dir="auto" style="text-align: start;">
"mobile"
</div>
</div>
#Illustration C
<div class="quantity">
<div class="color">...</div>
<span class="num">10</span>
</div>
Hello there! I am currently experimenting with using selenium to parse content from HTML. So far, I have successfully extracted the data for illustrations A and B using the following code:
data1 = driver.find_elements_by_css_selector("span[class='leveltwo']")
data2 = driver.find_elements_by_css_selector("div[class='itemlist']")
I was able to retrieve "Blue" for illustration A and "mobile" for illustration B. The given HTML examples are only for demonstration purposes, as I have scraped all elements matching the specified classes.
However, when attempting to extract the value "10" from the third illustration, I encountered some difficulties. I tried using the following methods:
data3a = driver.find_elements_by_css_selector("div[class='quantity']")
data3b = driver.find_elements_by_css_selector("span[class='num']")
data3c = driver.find_element_by_class_name("num")
Unfortunately, all attempts resulted in an empty list. I suspect this could be due to the absence of the dir
attribute in illustration C. Can anyone suggest the correct approach to extract the "10" value from this specific example?