我一直把头撞在墙上...有人可以帮我动脑筋来争取职位要求吗?
我正在尝试在网站上工作,但首先我必须要经过登录...我一直在使用Google进行搜索,但是到目前为止我仍无法对其进行整理。我对Web东西超级n00b,但是在Maya中对python有一定的经验。
这是我到目前为止所拥有的
import requests
login_url = 'https://example.com/examplelogin
login_payload = {'j_username':'myusername', 'j_password':'mypassword'}
with requests.Session() as s:
r = s.post(login_url, data = login_payload)
这是我要填写的表格:
<form id="login" action="/idp/Authn/UserPassword" method="post">
<p class="customError"></p>
<section>
<input id="username" class="form-element form-field" name="j_username" type="text" value="" placeholder="email address"></section>
<section>
<input id="password" class="form-element form-field" name="j_password" type="password" value="" placeholder="password"></section>
<button class="form-element form-button" type="submit">Login</button>
</form>
对于r.status_code
我得到200
不过r.text
就是登录页面的HTML ...它不记录我,然后给我通过...
我想念什么?
如果该站点没有某种API,则可能无法使用请求库进行访问。您应该查看Selenium,它将允许您使用FireFox来访问页面。如果您想要一个通常更快的无头版本,可以使用phantomjs。
from selenium.webdriver.firefox.webdriver import WebDriver
driver = WebDriver()
driver.get('https://example.com/examplelogin')
username = driver.find_element_by_id('username')
password = driver.find_element_by_id('password')
username.send_keys('MY_USERNAME')
password.send_keys('MY_PASSWORD')
submit.click()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句