【发布时间】:2015-06-13 21:35:20
【问题描述】:
在 chrome 和 firefox 中,一切都很好,直到我需要提取文本。我收到此错误:
h3 = next(element for element in h3s if element.is_displayed())
StopIteration
我什至添加了流畅的等待。
browser = webdriver.Firefox()
browser.get('https://www.voilanorbert.com/')
inputElement = browser.find_element_by_id("form-search-name")
inputElement.send_keys(leadslist[i][0])
inputElement = browser.find_element_by_id("form-search-domain")
inputElement.send_keys(leadslist[i][1])
searchbutton = browser.find_element_by_name("search")
searchbutton.click()
wait = WebDriverWait(browser, 20)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.results")))
wait2 = WebDriverWait(browser, 3000, poll_frequency=100, ignored_exceptions=[ElementNotVisibleException])
wait2.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "h3.one")))
h3s = browser.find_elements_by_css_selector('h3.one')
h3 = next(element for element in h3s if element.is_displayed())
result = h3.text
我认为这是因为它实际上并没有提取任何东西,所以它只是一个空列表。 一些可能会有所帮助的图片: 这是之前的图:
这是后图:
我需要提取“结果”类的“文本中心显示”类中的内容。
【问题讨论】:
-
您正在寻找 H3 元素,但我在 HTML 代码中看不到任何元素。请提供更多详细信息。
-
见上面的新图片。
-
我不懂 Python,如果我想出一个可行的 C# 解决方案对您有帮助吗?
-
不必在 python 中...只要您的解决方案不包含不在 python 中的函数。我应该可以从那里去。
标签: python css selenium web-scraping