抓取不起作用 - InvalidSelectorException:消息:无效的选择器:指定了无效或非法的选择器
scraping not working - InvalidSelectorException: Message: invalid selector: An invalid or illegal selector was specified
我正在尝试抓取雅虎财经网页(评论部分)。我想点击一个按钮,其 class 如下图所示:
我想 select 使用以下代码的按钮,但我得到的是 InvalidSelectorException
。我不明白为什么。
请注意,在我的代码中,我已将 space 替换为 .
,因为这是我通常所做的,但我也尝试过不替换 space,并且在这两种情况下它不工作。
link = 'https://finance.yahoo.com/quote/AMD/community?p=AMD'
path = r"""chromedriver.exe"""
driver = webdriver.Chrome(executable_path=path)
driver.get(link)
driver.find_element_by_class_name('sort-filter-button.O(n):h.O(n):a.Fw(b).M(0).P(0).Ff(i).C(#000).Fz(16px)')
您可以查看以下内容
#This page is taking more time to load
sleep(15)
element = driver.find_element_by_xpath("//button[@aria-label='Sort Reactions']")
element.click()
更新
element = driver.find_element_by_xpath("//button[contains(@class,'sort-filter-button')]")
element.click()
我正在尝试抓取雅虎财经网页(评论部分)。我想点击一个按钮,其 class 如下图所示:
我想 select 使用以下代码的按钮,但我得到的是 InvalidSelectorException
。我不明白为什么。
请注意,在我的代码中,我已将 space 替换为 .
,因为这是我通常所做的,但我也尝试过不替换 space,并且在这两种情况下它不工作。
link = 'https://finance.yahoo.com/quote/AMD/community?p=AMD'
path = r"""chromedriver.exe"""
driver = webdriver.Chrome(executable_path=path)
driver.get(link)
driver.find_element_by_class_name('sort-filter-button.O(n):h.O(n):a.Fw(b).M(0).P(0).Ff(i).C(#000).Fz(16px)')
您可以查看以下内容
#This page is taking more time to load
sleep(15)
element = driver.find_element_by_xpath("//button[@aria-label='Sort Reactions']")
element.click()
更新
element = driver.find_element_by_xpath("//button[contains(@class,'sort-filter-button')]")
element.click()