'Not able to scrape second sound file from website

I am trying to scrape those 2 engine sounds marked below in red. Apparently, link to that sound file changes to second sound file only when you click on play button(of second sound). My code below only gets me 1st sound, I even tried using click() function with no success. what change do I make to get that second sound ?

website link: https://www.akrapovic.com/en/car/product/15697/Chevrolet/Corvette-Stingray-Grand-Sport-C7/Slip-On-Line-Titanium?brandId=21&modelId=737&yearId=5445

    try:
        print(driver.find_element(By.XPATH, '//audio').get_attribute('src'))
        trial_page.append([driver.find_element(By.XPATH, '//audio').get_attribute('src')])
        Page_Audio = driver.find_element(By.XPATH, '//audio').get_attribute('src')  # COLLECT THIS VALUE
        # tech_data_table = driver.find_elements(By.XPATH , '//*[@class="table mt-5"]')
    except Exception as e:
        print("\n Oops! This page does not have any sound")
        Page_Audio = 'NONE'  # COLLECT THIS VALUE

enter image description here



Solution 1:[1]

I see there is only one audio element, which implies that the mp3 file name (the src attribute) should change for each of the audio. DOM Snapshot

But I see that for both the audios (I click played each audio and checked the file path in DOM) the filename is same, in which case the code will fetch the same audio link. DOM Snapshot for each audio played

Here is the code I have tried, and it fetched the same too.

driver.find_element(By.XPATH, ("(//section[contains(@class, 'sound container-xl')]//img[@alt='Play sound'])[1]")).click()
time.sleep(1)
first_audio = driver.find_element(By.XPATH, "//section[contains(@class, 'sound container-xl')]//audio").get_attribute('src')
time.sleep(3)
driver.find_element(By.XPATH, ("//section[contains(@class, 'sound container-xl')]//img[@alt='Pause sound']")).click()
time.sleep(3)
driver.find_element(By.XPATH, ("(//section[contains(@class, 'sound container-xl')]//img[@alt='Play sound'])[2]")).click()
time.sleep(1)
second_audio = driver.find_element(By.XPATH, "//section[contains(@class, 'sound container-xl')]//audio").get_attribute('src')
time.sleep(3)
driver.find_element(By.XPATH, ("//section[contains(@class, 'sound container-xl')]//img[@alt='Pause sound']")).click()
time.sleep(3)
print(f"First audio sound path {first_audio}")
print(f"Second audio sound path {second_audio}")

Output:

First audio sound path https://d1sfhav1wboke3.cloudfront.net/ImageServer/Apim2media/Documents/15697/a03e1e325a074f03a3a4dd1fcbfe11bd.mp3
Second audio sound path https://d1sfhav1wboke3.cloudfront.net/ImageServer/Apim2media/Documents/15697/a03e1e325a074f03a3a4dd1fcbfe11bd.mp3

Process finished with exit code 0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anand Gautam