【发布时间】:2020-12-26 03:06:46
【问题描述】:
我想让 Selenium 浏览 this page 导航栏的项目,然后检索其内容并将它们传递给 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()
【问题讨论】:
-
这意味着另一个元素正在接收点击使用 driver.executescript() 来定位并点击该元素。
标签: selenium web-scraping selenium-chromedriver