【问题标题】:Selenium post request pythonSelenium 发布请求 python
【发布时间】:2020-06-02 00:00:03
【问题描述】:

我需要登录一个网站,但是,它有一个隐藏的 recaptcha 字段,我不能使用 send_keys(元素不可交互)。是否有可能使用 selenium 或 selenium 请求发出 POST 请求?

【问题讨论】:

    标签: python selenium web-scraping python-requests


    【解决方案1】:

    使用 Python,您应该能够使用如下内容:

    webdriver = Firefox()
    response = webdriver.request('POST', 'url', data={"x": "y"})
    

    或者,通过 JavaScript 执行 POST 请求:

    jsrequest = '''var xhr = new XMLHttpRequest();
    xhr.open('POST', '{{URL}}', false);
    xhr.send(param1=value&param2=value2');
    return xhr.response;'''
    
    result = driver.execute_script(jsrequest);
    

    【讨论】:

    • 感谢 Josh 的快速响应,但显然,当以这种方式发出请求时,浏览器窗口会出现以下奇怪的行为:1 - 在 url 数据中打开 :, 2 - 在网站首页 3 - 关闭选项卡并返回日期 :,
    • 在对 selenium 的请求已经访问了会话启动并且用户登录的页面之后,是否可以提出请求并使用会话?
    • 您可以在 JavaScript 中将 POST 请求构造为 XMLHttpRequest,然后通过 Selenium 执行该脚本。请参阅对答案的编辑。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-31
    • 2021-03-28
    • 1970-01-01
    相关资源
    最近更新 更多