gpt4 book ai didi

python - 使用脚本登录网站

转载 作者:行者123 更新时间:2023-11-28 22:39:48 25 4
gpt4 key购买 nike

我实际上正在编写一个 Windows 脚本,单击该脚本将打开我的默认 Web 浏览器,打开一个页面,输入我的登录详细信息,然后提交表单。

到目前为止我所能做的就是用这个打开浏览器:

explorer http:\\outlook.com\website.com

由于我找不到任何说明如何执行此操作的资源,我查看了 python 脚本并找到了两个库,即。 urllibwebbrowser。我知道 urllib 用于抓取网站。但我不确定如何在网络浏览器中模拟相同的内容。 webbrowser 库只有在新标签页中打开页面的命令等。

请告诉我如何使用 python 或 windows 脚本完成此任务。

编辑:我将我的用户名和密码保存在我的浏览器中,以便自动填充。我只想模拟“ENTER”按键。

最佳答案

国际电联

对我来说,从 Python 控制浏览器最容易使用的选项是 IEC .我发现像您描述的那样简单的事情非常容易使用。

IEC is a python library designed to help you automate and control an Internet Explorer window. You can use this library to navigate to web pages, read the values of various HTML elements, set the values of checkboxes, text boxes, radio buttons etc., click on buttons and submit forms.

Typical uses for this library include:

  • Writing test scripts to check your web application automatically.

  • Managing an online account automatically.

  • Automatically logging and downloading webmail.

  • Monitoring web based applications periodically for failure.

Selenium

如果您不想使用 Internet Exporer(谁不想呢?),那么您可以使用 selenium。要安装它,请执行以下操作:

$ pip install -U selenium

this question 上有关于如何使用 Chrome 使用 selenium 登录网站的详细信息| .重要的部分是:

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

chromedriver = 'C:\\chromedriver.exe'
browser = webdriver.Chrome(chromedriver)
browser.get('http:\\outlook.com\website.com')

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

username.send_keys("YourUsername")
password.send_keys("Pa55worD")

selenium.find_element_by_name("submit").click()

关于python - 使用脚本登录网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34393353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com