小编Joh*_*Doe的帖子

Python(Selenium):如何使用登录重定向/组织登录登录网站

我不是专业的程序员,所以请原谅任何愚蠢的错误——我正在做一些研究,我正在尝试使用 Selenium 登录到一个数据库来搜索大约 1000 个术语。

我有两个问题: 1. 如何在重定向到第 2 页上的组织标志后使用 Selenium 登录。如何搜索数据库

在我解决 1 之前,我无法真正得到 2,所以我真的只询问 1。

这是我到目前为止的代码:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

path_to_chromedriver = 'C:/Users/Kyle/Desktop/chromedriver' # change path as needed
browser = webdriver.Chrome(executable_path = path_to_chromedriver)
url = 'http://library.universityname.edu/corpaffils'
browser.get(url)

username = selenium.find_element_by_id("login_id")
password = selenium.find_element_by_id("login_password")

username.send_keys("my username")
password.send_keys("my password")

selenium.find_element_by_name("submit").click()
Run Code Online (Sandbox Code Playgroud)

当我导航到上述 URL 时,它会将我定向到我的组织登录页面(例如 login.universityname.edu),我应该能够在其中输入我的用户名和密码,然后它会将我定向到数据库,但是当我执行上面的代码时,它并没有让我登录。

我可以在组织登录页面上找到的 html 如下所示:

<li><label for="login_id">ID:</label><input id="login_id" placeholder="ID" type="text" NAME="user" SIZE="20" VALUE=""/></li>
...
...
<li><label for="login_password">Password:</label><input id="login_password" placeholder="Password" type="password" NAME="pass" SIZE="20" /></li>
... …
Run Code Online (Sandbox Code Playgroud)

python selenium web-scraping

2
推荐指数
1
解决办法
7079
查看次数

标签 统计

python ×1

selenium ×1

web-scraping ×1