Используя Python3, я пытаюсь заставить Chrome Webdriver и Selenium идентифицировать различные категории «Объявления» на веб-странице www.jtinsight.com и оттуда распечатать названия категорий. На данный момент, используя приведенный ниже код, я могу распечатать первые два - «Все категории» и «Автомобили (частные)». Я определил, что HTML для этих двух отличается от других, и попробовал несколько различных строк кода, которые я перечислил в закомментированном коде, но не могу определить правильный тег / class / xpath и т. Д.
Любая помощь будет оценена.
from selenium import webdriver
from selenium.webdriver.common.by import By
# Creating the WebDriver object using the ChromeDriver
driver = webdriver.Chrome()
# Directing the driver to the defined url
driver.get("https://www.jtinsight.com/JTIRA/JTIRA.aspx#!/main")
# Locate the categories
# Each code line runs but only returns the first two categories
# categories = driver.find_elements_by_xpath('//div[@class="col-md-3 col-sm-4 col-xs-6"]')
# categories = driver.find_elements_by_xpath('//div[@class="mainCatEntry"]')
# categories = driver.find_elements_by_xpath('//div[@class="Description"]')
# Process ran but finished with exit code 0
# categories = driver.find_elements_by_xpath('//*[@class="col-md-3 col-sm-4 col-xs-6 ng-scope"]')
# categories = driver.find_elements_by_xpath('//div[@class="col-md-3 col-sm-4 col-xs-6 ng-scope"]')
# categories = driver.find_elements_by_partial_link_text('//href[@class="divLink"]')
# categories = driver.find_elements_by_tag_name('bindonce')
# categories = driver.find_elements_by_xpath('//div[@class="divLink"]')
# Error before finished running
# categories = driver.find_elements(By.CLASS_NAME, "col-md-3 col-sm-4 col-xs-6 ng-scope")
# categories = driver.find_elements(By.XPATH, '//div bindonce[@class="col-md-3 col-sm-4 col-xs-6 ng-scope"]')
# categories = driver.find_elements_by_class_name('//div bindonce[@class="col-md-3 col-sm-4 col-xs-6 ng-scope"]')
# Print out all categories on current page
num_page_items = len(categories)
print(num_page_items)
for i in range(num_page_items):
print(categories[i].text)
# Clean up (close browser once task is completed.)
driver.close()