我面临着一个奇怪的挑战-可能与我对html的理解不足有关。
我需要从网站上提取一些数据。但是尽管过去我在其他几个此类应用程序中使用了类似的代码,但我还是无法通过登录步骤。我只是无法使用任何get_element_by _ *()方法来定位用户名或密码元素。最近24小时,我一直在尝试各种事物和研究事物。我确定我在这里做的是根本上错误的事情-但无法弄清楚是什么。我有非常相似的代码,可以轻松登录到其他网站(http://courtbooking.bayclubs.com)。
帮助!我正在复制n-粘贴我的代码的相关部分
url = "https://www.ussquash.com/serve/?program=login"
inp_username = "my-username"
inp_password = "my-password"
try:
options = webdriver.ChromeOptions()
options.add_argument('headless')
driver = webdriver.Chrome(chrome_options=options)
except:
print("No web driver")
exit()
try:
driver.get(url)
except:
print("Could not load URL")
exit()
time.sleep(wait_time_in_seconds)
try:
#user = driver.find_element_by_id("login")
user = driver.find_element_by_name("username")
except Exception as e:
print("No username element, error {}".format(e))
exit()
else:
print("Username element found")
try:
password = driver.find_element_by_id("loginpass")
except Exception as e:
print("No password element, error {}".format(e))
exit()
else:
print("Password element found")
try:
signon_button = WebDriverWait(driver, wait_time_in_seconds).until(
EC.presence_of_element_located((By.CLASS_NAME, "btn btn-primary login-btn")))
except:
print("No signon element")
exit()
else:
print("Signon element found")
print("Logging in with username: %s, password: %s", inp_username, inp_password)
user.clear()
user.send_keys(inp_username)
password.clear()
password.send_keys(inp_password)
signon_button.click()
答案 0 :(得分:0)