【发布时间】:2020-06-02 22:59:58
【问题描述】:
我正在学习 python 并尝试从 python.org 粘贴搜索结果。我正在使用Selenium。
我想做的步骤:
- 打开 python.org
- 搜索术语“数组”(显示结果)
- 粘贴搜索项列表 (print("searchResults"))
我的代码:
from selenium import webdriver
import time
driver = webdriver.Chrome(executable_path="/usr/local/bin/chromedriver")
#waiting to find the element before throwing error no element found
driver.implicitly_wait(10)
#driver.maximize_window()
#getting the website
driver.get("https://www.python.org/")
driver.implicitly_wait(5)
#finding element by id
driver.find_element_by_id("id-search-field").send_keys("arrays")
driver.find_element_by_id("submit").click()
print("Test Successful")
SearchResults = driver.find_element_by_xpath("/html/body/div[1]/div[3]/div/section/form/ul")
print(SearchResults.text)
-> 这将粘贴所有结果。
现在我想要单个结果项及其标题。当我在现场检查搜索结果时,我得到了这个:<a href="/dev/peps/pep-0209/">PEP 209 -- Multi-dimensional Arrays</a>
没有可使用的标签、类和名称。
如何使用它来获取所有标题?
【问题讨论】:
标签: python selenium xpath css-selectors webdriverwait