我想在循环中对现有网页执行某些操作
Selenium将为您完成所有这些,还有更多!以下是使用Firefox的示例;你可以轻松使用Chrome,IE等
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
wd = webdriver.Firefox(executable_path="C:/Utility/geckodriver.exe", firefox_profile=profile)
url = "https://www.google.com/"
wd.get(url)
# download geckodriver for windows 64-bit from here
# https://github.com/mozilla/geckodriver/releases
你需要关注这样的事情:
find_element_by_class_name(name)
Finds an element by class name.
Args:
name: The class name of the element to find.
Returns:
WebElement - the element if it was found
Raises:
NoSuchElementException - if the element wasn’t found
Usage:
element = driver.find_element_by_class_name('foo')
有关详细信息,请参阅以下链接。