import time
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
browser = Chrome('C:/Users/User/PycharmProjects/pythonProject1/уроки/Отключение режима WebDriver/chromedriver.exe')
url = 'https://bus.gov.ru/registry'
browser.get(url)
input_tab = browser.find_element(By.XPATH, '/html/body/div[2]/ui-view/ui-view-ng-upgrade/ui-view/app-registry/app-registry-filter/form/div[1]/div[1]/label/div[2]/input')
input_tab.send_keys('онкологический диспансер')
input_tab.send_keys(Keys.ENTER)
time.sleep(3)
soup = BeautifulSoup(browser.page_source, 'lxml')
soup = soup.find_all('div', class_='result ng-star-inserted')
data = []
for li in soup:
name = li.find('a', class_='result__title').text
phone = li.find('p', class_='result__phone').text
link = li.find('a', class_='result__url-link').get('herf')
data.append([link, name, phone])
for i in data:
for z in i:
print(z)
print('')
при:
link = li.find('a', class_='result__url-link').get('herf')
выдает:
File "C:\Users\User\PycharmProjects\pythonProject1\уроки\selenium_1\1.py", line 29, in
link = li.find('a', class_='result__url-link').get('herf')
AttributeError: 'NoneType' object has no attribute 'get'
при:
link = li.find('a', class_='result__url-link').text
выдает:
File "C:\Users\User\PycharmProjects\pythonProject1\уроки\selenium_1\1.py", line 29, in
link = li.find('a', class_='result__url-link').text
AttributeError: 'NoneType' object has no attribute 'text'
при том что:
link = li.find('a', class_='result__url-link')
выдает:
<a _ngcontent-ren-c388="" class="result__url-link" href="http://bronkodisp.brkmed.ru"> http://bronkodisp.brkmed.ru </a>