вот мой код:
из селена импорта webdriver
из bs4 import BeautifulSoup
driver = webdriver. Chrome ('H : \ datascience-python \ selinium \ chromedriver.exe ')
driver.get (' https://www.aljazeera.com/news/ ')
button = driver.find_element_by_id (' btn_showmore_b1_418 ' )
driver.execute_script ("arguments [0] .click ();", кнопка)
content = driver.page_source
soup = BeautifulSoup (content, 'html .parser ')
container = soup.select (' div.topics-se c -item-cont ')
titlelist = []
urllist = []
для элементов в контейнере:
if items is not None:
title = items.find_element_by_xpath('//div[@class="col-sm-7 topics-sec-item-cont"]/a/h2').text
url = items.find_element_by_xpath('//div[@class="col-sm-7 topics-sec-item-cont"]/a')
titlelist.append(title)
urllist.append(url.get_attribute('href'))
print(str(titlelist) + '\n')
print(str(urllist) + '\n')
это дает мне эту ошибку:
TypeError Traceback (самая последняя последний вызов)
in
18 for items in container:
19 if items is not None:
---> 20 title = items.find_element_by_xpath ('// div [@ class = "col-sm-7 themes-se c -item-cont "] / a / h2 '). text
21 url = items.find_element_by_xpath('//div[@class="col-sm-7 topics-sec-item-cont"]/a')
22
TypeError: объект' NoneType 'не может быть вызван