I would like to loop over the elements from this website https://www.dccomics.com/comics
At the bottom of the webpage there is a browse comics section, I would like to scrape the names from each comic
This is the code I have at the moment
# imports
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
# website urls
base_url = "https://www.dccomics.com/"
comics_url = "https://www.dccomics.com/comics"
# Chrome session
driver = webdriver.Chrome("C:\\laragon\\www\\Proftaak\\chromedriver.exe")
driver.get(comics_url)
driver.implicitly_wait(500)
cookies = driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[4]/div[2]/div/button')
driver.execute_script("arguments[0].click();", cookies)
driver.implicitly_wait(100)
clear_filter = driver.find_element_by_class_name('clear-all-action')
driver.execute_script("arguments[0].click();", clear_filter)
array = []
for titles in driver.find_elements_by_class_name('result-title'):
title = titles.find_element_by_xpath('/html/body/div[2]/section/section/div[2]/div/div/div/div/div[3]/div[7]/div[2]/div/div/div/div/div[3]/div[3]/div[2]/div[1]/a/p[1]').text
array.append({'title': title,})
print(array)
driver.quit()
I am using the xpath below:
/html/body/div[2]/section/section/div[2]/div/div/div/div/div[3]/div[7]/div[2]/div/div/div/div/div[3]/div[3]/div[2]/div[1]/a/p[1]
This works but only gets the first element of the result-title CSS class, in this case 818.
How would I loop through each result-title class using either the CSS selector or Xpath?