Цель этого кода - очистить многостраничную таблицу данных с определенного URL-адреса. И больше не работало только для первого ряда.
Вот код:
from selenium import webdriver
class DataEngine:
def __init__(self):
self.url = 'https://www.investing.com/economic-calendar/house-price-index-147'
self.driver = webdriver.PhantomJS(r"D:\Projects\Tutorial\Driver\phantomjs-2.1.1-windows\bin\phantomjs.exe")
def title(self):
self.driver.get(self.url)
title = self.driver.find_elements_by_xpath('//*[@id = "leftColumn"]/h1')
for title in title:
print(title.text)
def table(self):
self.driver.get(self.url)
while True:
table = self.driver.find_elements_by_xpath('//*[@id = "historicEvent_372690"]')
for table in table:
print(table.text)






Чтобы гарантировать, что ваш код очищает все строки на странице, обновите xpath
//*[@id = "historicEvent_372690"]
к
//*[contains(@id,"historicEvent_")]
Используемый вами xpath считывает только первую строку. В xpath, который я поделился, используется ключевое слово contains, которое ищет все элементы, содержащие идентификатор historicEvent_.
Какой многостраничная таблица данных вы пытаетесь очистить?