1

I'm trying to scrape this URL: https://www.wheel-size.com/size/acura/mdx/2001/

The values that I want to scrape are loaded dynamically e.g Center Bore If you open the link in normal browser the content is loaded just fine but if I use Selenium(chromedriver) it just keeps loading and the values are never displayed.

Any idea how can I scrape it? Below is the picture of how it looks like. You can also see the loading for 1-2 seconds when you open the link in normal browser.

screenshot of chromedriver

1 Answers1

1

To extract the desired texts e.g. 64.1 mm, 5x114.3 etc as the elements are Google Tag Manager enabled elements you need to induce WebDriverWait for the visibility_of_element_located() and you can use the following locator strategies:

options = Options()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument('--disable-blink-features=AutomationControlled')
s = Service('C:\\BrowserDrivers\\chromedriver.exe')
driver = webdriver.Chrome(service=s, options=options)
driver.get('https://www.wheel-size.com/size/acura/mdx/2001/')
print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//span[contains(., 'Center Bore')]//following::span[1]"))).text)
print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//span[contains(., 'PCD')]//following::span[1]"))).text)

Console Output:

64.1 mm
5x114.3

Note : You have to add the following imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

You can find a relevant discussion in How to retrieve the text of a WebElement using Selenium - Python

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for the help. I tried this approach and your code as well but I get empty strings in the console. The issue is the values are never displayed on web when I visit via selenium driver. It just keeps loading as shown in picture of my post. Could you confirm if you got the values in console? – Talha Irfan Mar 27 '22 at 17:38
  • Checkout the updated answer and let me know the status. – undetected Selenium Mar 27 '22 at 19:37
  • 1
    Damn it worked <3 Thanks a lot! What are those parameters that you added in the options? I'm grateful for your help. – Talha Irfan Mar 27 '22 at 20:20
  • @TalhaIrfan Avoiding [ChromeDriver initiated _Chrome Browser_ geting detected](https://stackoverflow.com/a/62520191/7429447) – undetected Selenium Mar 27 '22 at 20:21