Home > database >  How to extract the price in selenium if they have same tag?
How to extract the price in selenium if they have same tag?

Time:05-14

enter image description here

I would like to get first prices ($916.65) in pyhton but I do not know which method do I need to apply ? Each price has the same tag (div ). Should I think like this is the frame or table and do I need to find this price by selecting row ? or do I need to take a screenshoot at this point ? Any help, any direction would be appreciated.

CodePudding user response:

Firstly, you can download the plugin to get XPath of this html tag. SelectorGadget, XpathFinder are almost useful. Secondly, getElementByXpath or similar method can be use to get price.

CodePudding user response:

I thought you could get the list of the element "price" and also get the value of this class.

Find all elements with class name is "price":

elements = element.find_elements(By.CLASS_NAME, 'price')

This will return a list of WebElement, then iterate the list and get the one you want

for e in elements:
print(e.text)

But, I not sure this will help you get the first price, because the page maybe load the second price before first price and so that the code will get the second price fisrt > first price > third > so on....

Therefore, I suggest you should to wait the page load complete before perform get the list of prices

Hope this will help !

  • Related