参考链接:https://blog.csdn.net/Haven200/article/details/103208795
首先:
pip3 install selenium
然后在https://github.com/mozilla/geckodriver/releases/中选择合适的版本,解压后得到一个名为geckodriver的文件,然后执行:
mv geckodriver /usr/local/bin/
以下有:driver = webdriver.Firefox()
driver.get("https://blog.csdn.net/“)
driver.close()
un=driver.find_element_by_id("un")
txt= driver.find_element_by_link_text("hahahaha")
cl=driver.find_element_by_class_name( "btn_class" )
driver.find_element_by_xpath( "//a[@id='btn_apply' and @class='btn_class']" )
un.click()
un.send_keys("123456")
zi=driver.find_element_by_xpath("//iframe[@id='maincontent']")
driver.switch_to.frame( iframe )
driver.switch_to.default_content()
#!/usr/bin/env python3
# coding=utf-8
import time
from selenium import webdriver
print("初始化 FirefoxDriver,并打开 Firefox")
driver = webdriver.Firefox()
print("打开 shixuen.com 网址")
driver.get("https://pass.hust.edu.cn/cas/login?service=http%3A%2F%2Fhub.hust.edu.cn%2Fhustpass.action")
print("搜索指定文本的链接")
un = driver.find_element_by_id("un")
pd=driver.find_element_by_id("pd")
code=driver.find_element_by_id("code")
go=driver.find_element_by_id("index_login_btn")
un.send_keys("M209913949")
time.sleep(5)
pd.send_keys("23551166")
time.sleep(5)
code.send_keys("4561")
time.sleep(5)
print("点击此链接")
go.click()
time.sleep(10)
print("关闭浏览器")
driver.close()
下一篇:https://blog.csdn.net/wxkhturfun/article/details/111463461