0

这是链接:“https://btlaesthetics.com/en/find-a-physician”

我使用 selenium 在位置搜索框中搜索了一个邮政编码“6292”(如下面的代码所示)。它搜索并显示结果。现在它逐个点击每个诊所(部分)的“显示详细信息”,它会这样做,但我面临的主要问题是,它每次都会刮取第一部分的数据(电话、电子邮件、网站)它点击每个部分的详细信息,而不是抓取每个部分自己的数据。这是代码:

from selenium import webdriver
from bs4 import BeautifulSoup
import time


options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(executable_path='D:\python\chromedriver\chromedriver.exe', options=options)
driver.get("https://btlaesthetics.com/en/find-a-physician")
driver.maximize_window()

element = driver.find_element_by_xpath("//input[@class='inp-text filter-address-input pac-target-input']")
element.send_keys("6292")
element.send_keys(u'\ue007')
element.send_keys(u'\ue007')
element.send_keys(u'\ue007')
element.send_keys(u'\ue007')
element.send_keys(u'\ue007')
element.send_keys(u'\ue007')
element.send_keys(u'\ue007')
element.send_keys(u'\ue007')
element.send_keys(u'\ue007')
element.send_keys(u'\ue007')
element.send_keys(u'\ue007')
element.send_keys(u'\ue007')
time.sleep(3)

html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')

item_provider_near = soup.find_all('div', class_='item-provider')
for each in range(len(item_provider_near)):
    each = "(//a[@class='toggle-more'])[" + str(each+1) + "]"
    driver.find_element_by_xpath(each).click()
    time.sleep(3)
    phone = soup.find('span',class_='provider-phone').text
    email = soup.find('span',class_='provider-email').text
    website = soup.find('span',class_='provider-website').text
    if phone:
        print(phone)
    else:
        pass

    if email:
        print(email)
    else:
        pass

    if website:
        print(website)
    else:
        pass
driver.quit()

最后,抓取后显示错误:selenium.common.exceptions.elementnotinteractableexception 消息元素不可交互

4

0 回答 0