import time
from selenium import webdriver
a = webdriver.Chrome()
a.get('https://passport.zhihuishu.com/')
#正常情况 我们进行标签元素定位。是定位不到#document html嵌套里面的内容,所以我们必须先 切换到嵌套里面的内容,才能定位到想要的元素标签
# 找到我们想要的标签(嵌套标签)tag_name定位就是通过标签名来定位
iframe = a.find_element_by_tag_name('iframe')
# 切换到框架 到 iframe框架
a.switch_to.frame(iframe)
a.find_element_by_name('realName').send_keys('18844858026')
time.sleep(3)
a.find_element_by_name('code').send_keys('LewisDean546')
time.sleep(3)
a.find_element_by_id('wall-bg').click()
结果
D:\Python\p\Python\python.exe D:/Python/编程/自动登录.py
Traceback (most recent call last):
File "C:\Users\Lenovo\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\common\service.py", line 74, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "D:\Python\p\Python\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "D:\Python\p\Python\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] 系统找不到指定的文件。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/Python/编程/自动登录.py", line 4, in <module>
a = webdriver.Chrome()
File "C:\Users\Lenovo\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "C:\Users\Lenovo\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\chromium\webdriver.py", line 90, in __init__
self.service.start()
File "C:\Users\Lenovo\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\common\service.py", line 84, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home
进程已结束,退出代码为 1
你是要自动化拉取浏览器吧,最好单独下个driver吧,我用的gooledriver,你需要的话,我可以发你