content = driver.find_element_by_class_name('topics-sec-block') container = content.find_elements_by_xpath('//div[@class="col-sm-7 topics-sec-item-cont"]')
код ниже:
for i in range(0, 40): title = [] url = [] heading=container[i].find_element_by_xpath('//div[@class="col-sm-7 topics-sec-item-cont"]/a/h2').text link = container[i].find_element_by_xpath('//div[@class="col-sm-7 topics-sec-item-cont"]/a') title.append(heading) url.append(link.get_attribute('href')) print(title) print(url)
это дает мне 40 строк, но все строки имеют одинаковые заголовок и URL, как (некоторые из них приведены ниже):
['Stuck in Mexico: Central American asylum seekers in limbo'] ['https://www.aljazeera.com/news/2020/03/stuck-mexico-central-american-asylum-seekers-limbo-200305103910955.html'] ['Stuck in Mexico: Central American asylum seekers in limbo'] ['https://www.aljazeera.com/news/2020/03/stuck-mexico-central-american-asylum-seekers-limbo-200305103910955.html']