【问题标题】:send_keys Without Any Xpath没有任何 Xpath 的 send_keys
【发布时间】:2021-10-28 04:29:06
【问题描述】:

我有一个website,我想使用 Python 的 Selenium 登录。但我无法获得 xpath 或类似的东西。

那么,我该如何登录呢?我已经试过了:

DRIVER.find_element_by_tag_name('body').send_keys('test')

和

actions = ActionChains(DRIVER)
actions.send_keys('test')
actions.perform()

但两者都不起作用。

【问题讨论】:

标签: python selenium


【解决方案1】:

这是一个 HTTP 身份验证,而不是登录网页。

使用这样的东西:

from selenium import webdriver

username = 'myusername'
password = 'mypassword'
url = f'http://{username}:{password}@webtrash.musictunnel8080.de/'

options = webdriver.ChromeOptions()
options.add_argument('--disable-blink-features="BlockCredentialedSubresources"')

driver = webdriver.Chrome(options=options)
driver.get(url)

更新

使用requests包:

import requests
from requests.auth import HTTPBasicAuth

username = 'myusername'
password = 'mypassword'
url = 'http://webtrash.musictunnel8080.de/'
auth = HTTPBasicAuth(username, password)

r = requests.get(url, auth=auth)

【讨论】:

  • 不,它不工作......
  • 那么,问题出在哪里?您不能使用 Selenium 登录网站。
  • 当我打开新的 url 时,我仍然得到与上图相同的结果。它也无法正常浏览。
  • 您的用户名和密码对吗? :)
  • 是的,100% 确定
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-17
  • 2018-03-27
  • 1970-01-01
相关资源
最近更新 更多