我的 python 自动登录脚本无法执行

时间:2021-02-16 07:57:21

标签: python html selenium autologin

所以我刚开始学习python,我目前正在尝试制作一个简单的登录脚本:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
usernameStr = 'myusernamexxx'
passwordStr = 'mypasswordxxx'
browser = webdriver.Chrome()
browser.get(('https://myschoolwebsite.sch.id/login'))
username = browser.findElement(By.cssSelector("input[name='username']"))
username.send_keys(usernameStr)
password = browser.findElement(By.cssSelector("input[name='password']"))
password.send_keys(passwordStr)
submit_button = browser.findElement(By.cssSelector(".fa fa-sign-in"));
submit_button.click()

这里是html代码

<input type="hidden" name="ajaran" value="2020">
                                        <div class="row">
                                            <div class="col-lg-12 no-pdd">
                                                <div class="sn-field">
                                                    <input type="text" name="username" placeholder="Masukkan Username"  title="Masukkan Username " data-placement="right">
                                                    <i class="fa fa-user"></i>
                                                </div><!--sn-field end-->
                                            </div>
                                            <div class="col-lg-12 no-pdd">
                                                <div class="sn-field">
                                                    <input type="password" name="password" placeholder="Password" title="Masukkan Password  " data-placement="right">
                                                    <i class="fa fa-lock"></i>
                                                </div>
                                            </div>
                                            <div class="col-lg-12 no-pdd">
                                                <div class="checky-sec">
                                                    <div class="fgt-sec">
                                                        <input type="checkbox" name="cc" id="c1">
                                                        <label for="c1">
                                                            <span></span>
                                                        </label>
                                                        <small>Remember me</small>
                                                    </div><!--fgt-sec end-->
                                                    <a href="javascript:void(0)" title=""  data-toggle="modal" data-target="#myModal">Lupa Password?</a>
                                                </div>
                                            </div>
                                            
                                            <div class="col-lg-12 no-pdd">
                                                
                                                <button type="submit" value="submit"> <i class="fa fa-sign-in"></i> Login E-Learning</button>

我用pyinstaller创建了exe文件然后执行它,这是终端的输出:

DevTools listening on ws://127.0.0.1:61116/devtools/browser/9893efdb-866c-4b62-9e2f-70fbd91404f5
[10948:3652:0216/145009.846:ERROR:device_event_log_impl.cc(211)] [14:50:09.845] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[10948:3652:0216/145009.846:ERROR:device_event_log_impl.cc(211)] [14:50:09.851] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[10948:3652:0216/145009.950:ERROR:device_event_log_impl.cc(211)] [14:50:09.956] Bluetooth: bluetooth_adapter_winrt.cc:1072 Getting Default Adapter failed.

上面写着 failed to execute script,我使用的是 chrome 88 版。 帮助,我错过了什么?我想不通我的大脑快死了哈哈。

0 个答案:

没有答案