以下代碼使用css選擇器提取元素,它在ipython3終端中工作,但在腳本中運行時找不到元素:當以腳本運行時,selenium css選擇器或複雜類的xpath不起作用
from selenium import webdriver
driver = webdriver.Chrome()
url = scrape_url + "&keywords=" + keyword
driver.get(url)
driver.find_elements_by_css_selector(".search-result.search-result__occluded-item.ember-view")
的複雜類元素的:
"search-result search-result__occluded-item ember-view"
以下XPath在終端的工作,但不作爲腳本:
driver.find_elements_by_xpath("//li[contains(@class, 'search-result search-result__occluded-item')]")
XPath也沒有工作。對不起,我會在終端中更新 – mrbot