I need to fetch the product name from this link with selenium in python. I’ve tried everything and still can’t.
Help me please.
Hey @Paulo,
Here is an example for this particular case.
Using xpath along with contains
solves the problem.
Here is the code example:
from botcity.web import WebBot
class Bot(WebBot):
def action(self, execution=None):
# Configure whether or not to run on headless mode
self.headless = False
# Uncomment to change the default Browser to Firefox
# self.browser = Browser.FIREFOX
# Opens the BotCity website.
self.browse("https://www.americanas.com.br/produto/2917265060")
# Use xpath along with the contains function to search for the element which class attribute
# contains "product-title"
ele = self.driver.find_element_by_xpath("//span[contains(@class, 'product-title')]")
# Get the element text
print(ele.text)
# Wait for 2 seconds before closing
self.wait(2000)
# Stop the browser and clean up
self.stop_browser()
if __name__ == '__main__':
Bot.main()
If you run this code you will get the following output:
Smartphone Motorola Moto G30 128GB 4G Wi-Fi Tela 6.5’’ Dual Chip 4GB RAM Câmera Quádrupla + Selfie 13MP - Dark Prism
More info here: How to use regular expressions in xpath in Selenium with python?
Let me know if it works for you.