【发布时间】:2019-12-29 12:35:52
【问题描述】:
我已尝试使用 CSS 选择器在搜索框中使用 send_key() 函数发送值并提交,以便我获得特定年份的医生表列表,但出现以下错误 “ ElementNotInteractableException:消息:元素不可交互”
下面是我写的代码:
from selenium import webdriver
from bs4 import BeautifulSoup as bs
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
import time
url = "https://www.mciindia.org/CMS/information-desk/indian-medical-register"
driver = webdriver.Chrome(r"C:\chromedriver.exe")
driver.get(url)
driver.find_element_by_xpath("//a[contains(text(),'Year of Registration')]").click()
driver.find_elements_by_css_selector("input[type='text']")[-1].send_keys("2015")
driver.find_element_by_css_selector("input[value='Submit']").click()
next_page = True
while next_page == True:
soup = bs(driver.page_source, 'html.parser')
table1 = soup.find('table',{'id':'doct_info2'})
try:
rows = table1.find_all('tr')
for row in rows:
if len(row.find_all('td')) == 7:
data = row.find_all('td')
link = data[6].click()
soup2 = bs(link, 'html.parser')
table2 = soup2.find('table',{'id':'doctorBiodata'})
rows = table2.find_all('tr')
print(rows)
except:
pass
time.sleep(5)
try:
driver.find_element_by_xpath("//a[contains(text(),'Next')]").click()
except:
print ('No more pages')
next_page=False
driver.close()
【问题讨论】:
-
你想要
2015的整个搜索结果吗?以及每个doctor的全部数据?
标签: python-3.x selenium-webdriver beautifulsoup