selenium - Selenium 中的导航错误:链接在点 (...) 处不可点击。其他元素会收到点击
问题描述
我想让 Selenium 浏览此页面导航栏的项目,然后检索其内容并将它们传递给 beatifulsoup。
我的代码在第一页上运行良好,之后出现以下错误:
ElementClickInterceptedException: Message: element click intercepted: Element <a href="https://www.rollingstone.com/music/music-lists/500-greatest-songs-of-all-time-151127/smokey-robinson-and-the-miracles-shop-around-71184" style="color: rgb(211, 37, 49); padding: 4px 8px;">...</a> is not clickable at point (77, 73). Other element would receive the click: <div class="fc-dialog-overlay"></div>
以前的答案没有帮助。这是我的代码。我真的很感激任何帮助。
webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--incognito')
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)
target_page = 'https://www.rollingstone.com/music/music-lists/500-greatest-songs-of-all-time-151127/'
driver.get(target_page)
header = driver.find_element_by_id('pmc-gallery-list-nav-bar-render')
items = header.find_elements_by_tag_name('a')
songs = []
for item in items:
driver.maximize_window()
time.sleep(5)
item.click()
page_source = driver.page_source
soup = BeautifulSoup(page_source)
song_all = soup.find_all('h2', {'class':'c-gallery-vertical-album__title'})
for song in song_all:
songs.append(strip_extra_chars(song.get_text()))
driver.quit()
解决方案
让我们评论一下options.add_argument('--headless')
,看看程序是如何运行的。您需要确定哪个元素与您的链接重叠。例如,我尝试运行您的代码,然后出现此对话框:
在这种情况下,要禁用通知,您可以添加:
prefs = {"profile.default_content_setting_values.notifications": 2}
options.add_experimental_option("prefs", prefs)
但是此对话框与定位器不匹配.fc-dialog-overlay
,因此您的问题可能与另一个元素有关。你需要找到它。
另一种解决方法,可以点击使用jsdriver.execute_script()
推荐阅读
- python - 在 Reportlab、Python 上使用 np.array
- python - 有没有办法使用套接字从网站发送/查看数据?
- html - 需要基于 flexbox 的列,左侧是文本,右侧是图像
- sql - 存储过程返回的计数与同一查询不同
- c# - 使用 xamarin MediaPlayer 播放音频 url
- java - 将字符串转换为 Postgres 时间戳并返回
- c# - 将非实例化的类和接口传递给泛型方法
- csv - 选择所有 CSV,然后将所有内容粘贴到 Google 工作表 - 超时问题
- javascript - Mocha 动态测试生成与动态数据生成
- ios - Swift 4:如何在 UIView 中设置完整背景,包括导航栏?