在学习python爬虫时,使用selenium爬取天猫页面时,在爬取第三页时出现了错误。
错误为:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <span class="btn J_Submit" role="button" tabindex="0">...</span> is not clickable at point (834, 355). Other element would receive the click: <div class="row row-2 title">...</div>
(Session info: chrome=78.0.3904.108)
代码:
try:
url = 'https://s.taobao.com/search?q=' + quote(text)
browser.get(url)
if page > 1:
input = wait.until(
EC.presence_of_element_located((By.CSS_SELECTOR, '#mainsrp-pager div.form > input'))
)
submit = wait.until(
EC.element_to_be_clickable((By.CSS_SELECTOR, '#mainsrp-pager div.form>span.btn.J_Submit'))
)
input.clear()
input.send_keys(page)
submit.click() //我将其改成了submit.send_keys(Keys.ENTER)解决了这个问题
wait.until(
EC.text_to_be_present_in_element((By.CSS_SELECTOR,'#mainsrp-pager li.item.active > span'), str(page))
)
wait.until(
EC.presence_of_element_located((By.CSS_SELECTOR, '.m-itemlist .items .item'))
)
get_products()
except TimeoutException:
index_page(page)
原因未知,若有知道的可以告诉一下。