我想在網(wǎng)頁(yè)上找到文本元素(地址在下面)我對(duì) reddit 帖子標(biāo)題感興趣。(屏幕上有提示)我用Ctrl+ Shift+I和檢查單元,并獲得:<h2 class="s1ua9il2-0 hsWiTe" data-redditstyle="true">The problems of a dutchman in China.</h2>沒(méi)有 id 和 name。只有標(biāo)簽('h2')和類(“s1ua9il2-0 hsWiTe”),對(duì)嗎?我下面的代碼不起作用:import seleniumfrom selenium import webdriverfrom selenium.webdriver.common.keys import Keysoptions = webdriver.ChromeOptions()options.add_argument('headless')driver = webdriver.Chrome(r"C:\Users\vishniakov\Desktop\python bj\driver\chromedriver.exe",chrome_options=options)driver.get("https://www.reddit.com/r/funny/comments/9kxrv6/the_problems_of_a_dutchman_in_china/")print(driver.title)elem = driver.find_element_by_class_name("s1ua9il2-0 hsWiTe")#driver.quit()錯(cuò)誤:selenium.common.exceptions.InvalidSelectorException:消息:無(wú)效選擇器:不允許復(fù)合類名此外,當(dāng)我使用復(fù)制單擊時(shí),通過(guò) css_selector 查找也不起作用:
使用 Selenium Python 在網(wǎng)頁(yè)上找不到元素
BIG陽(yáng)
2021-06-29 09:04:45