简体   繁体   English

如何在 python 上获取 selenium web 驱动程序以在以下页面的 ZC7A628CBA22E28EB17B5F5C6AE2A26 上查找元素?

[英]How to get selenium web driver on python to find elements on css selectors of a following page?

I am trying to get selenium to web scrape the first paragraph of wiki pages using CSS selectors.我试图让 selenium 到 web 使用 CSS 选择器刮掉维基页面的第一段。

When I run this code, it seems to only select ones from the original web page当我运行此代码时,似乎只有 select 来自原始 web 页面

https://en.wikipedia.org https://en.wikipedia.org

and not what I am searching for, in this case 'cats'.而不是我正在寻找的东西,在这种情况下是“猫”。

Any help with this would be awesome!对此的任何帮助都会很棒!


browser = webdriver.Firefox(executable_path='D:\Import Files that I also want backed up\Jupyter Notebooks\Python Projects\Selenium\driverss\geckodriver.exe')
browser.get('https://en.wikipedia.org')

search_elem = browser.find_element_by_css_selector('#searchInput')

search_elem.send_keys('cats')
search_elem.submit()


results_elem = browser.find_element_by_css_selector('p')

print(results_elem.text)

output:

Adventure Time is an American fantasy animated television series created .....

To get the first paragraph text from wiki page.Induce WebDriverWait() and visibility_of_element_located () and following css selector.从 wiki 页面获取第一段文本。Induce WebDriverWait()visibility_of_element_located () 并遵循css选择器。

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

browser = webdriver.Firefox(executable_path='D:\Import Files that I also want backed up\Jupyter Notebooks\Python Projects\Selenium\driverss\geckodriver.exe')
browser.get('https://en.wikipedia.org')
search_elem = browser.find_element_by_css_selector('#searchInput')
search_elem.send_keys('cats')
search_elem.submit()
results_elem=WebDriverWait(browser,10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,"div.mw-parser-output p:nth-of-type(3)")))
print(results_elem.text)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python Selenium 获取页面源中的所有元素。 driver.find_elements(By.XPATH, "//*") - Python Selenium get all elements in page source. driver.find_elements(By.XPATH, "//*") 如何在python selenium中循环多个元素(不同的CSS选择器) - How to loop multiple elements in python selenium (different CSS selectors) 带有Firefox Web驱动程序的Selenium无法通过Python代码找到元素 - Selenium with Firefox web driver can not find elements by Python code Selenium Python driver.find.elements 获取属性 - Selenium Python driver.find.elements get attribute 如何通过使用 driver.find_elements(By.XPATH,'') 和 Python Selenium 来获取汽车名称 - How can i get car names by using driver.find_elements(By.XPATH,'') with Python Selenium 如何在 Z23EEEB4347BDD755BFC6B7EE9A 中使用 selenium firefox 和 chrome 驱动程序翻译 web 页面? - How to translate a web page using selenium firefox and chrome driver in python? Python Selenium Chrome驱动程序找不到元素 - Python Selenium Chrome Driver doesnt find elements 使用 Selenium 和 Python 查找网页上的所有元素 - Find all elements on a web page using Selenium and Python 使用 Selenium Python 在网页上找不到元素 - Can't find elements on web page using Selenium Python 如何通过同时调用不同的 css 选择器来抓取 Selenium/Python 中的元素? - How to scrape elements in Selenium/Python by calling different css selectors at the same time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM