На странице продукта есть 20 продуктов, сценарий очищает информацию о продукте, переходя на страницу сведений о продукте и обратно, но я не могу понять, как сделать сценарий очистки страниц 2,3 и 4 et c!?
Пожалуйста, помогите:)
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from bs4 import BeautifulSoup
import pandas as pd
#argument for incognito Chrome
option = webdriver.ChromeOptions()
option.add_argument(" — incognito")
browser = webdriver.Chrome(executable_path = "driver location goes here")
browser.get("https://www.rimi.lv/e-veikals/lv/produkti/piena-produkti-un-olas/c/SH-11")
xx_list = []
xxx_list = []
timeout = 20
elements =
WebDriverWait(browser,timeout).until(EC.visibility_of_all_elements_located((By.XPATH,
'//[@id="main"]/section/div[1]/div/div/div/div/div[2]//a')))
for element in elements:
#get href
href = element.get_attribute('href')
#open new window with specific href
browser.execute_script("window.open('" +href +"');")
# switch to new window
browser.switch_to.window(browser.window_handles[1])
#......now you are on the new window, scrape here
#example to scrape 'title' in the new window
xx = WebDriverWait(browser,timeout).until(EC.visibility_of_element_located((By.CLASS_NAME, "name")))
print(xx.text)
xxx = WebDriverWait(browser, timeout).until(EC.visibility_of_element_located((By.XPATH, "//*[@id='main']/section/div[1]/div/div/section[1]/div/div[2]/div[1]/div[2]/ul/li/p")))
print(xxx.text)
#close the new window
browser.close()
#back to main window
browser.switch_to.window(browser.window_handles[0])