【问题标题】:Python Click Different ButtonsPython单击不同的按钮
【发布时间】:2014-11-15 17:20:09
【问题描述】:

有没有一种方法或方法可以单击 Python 中的两个不同按钮之一?这两个按钮的相关HTML代码是:

<input type="text" id="target" name="target" size="80" value="https://gj3s.inklingmarkets.com/user/good_judgment_authentication?u="style=\'display:none;\'>\n
<input type="button" id="training" name="training" style="width:200px;" value="Continue to Training" onclick="window.open(\'tr_redir.php\');" />&nbsp;&nbsp;
<input type="button" id="continue" name="continue" style="width:200px;" value="Continue to Forecasting Site"  onclick="pm_go();" />

手动访问网站时需要单击的按钮是 id="continue" 和 onclick="pm_go();" 的第二个(最后一行) 我尝试使用 requests post 和 get 方法但没有成功。

import requests
s = requests.Session()
r = s.post(Log_URL, data={"target":'https://gj3s.inklingmarkets.com/memberships/2010/profile'})

脚本 pm_go 提供目标网页

function pm_go(){
    var target_path = document.getElementById('target').value;
    if( target_path == '' ){
        alert("A target path is not yet defined for this Condition.");
    } else {
document.location = "pm_redir.php?target=" + target_path;
}

【问题讨论】:

  • 方法是通过观察浏览器的net选项卡中的请求。您提供的信息无法帮助我们回答这个问题 - 请您提供网站链接,然后建议要做什么 - 我应该可以提供帮助
  • @md-mohsin,根据您的要求,我尝试添加详细信息; “在浏览器的 net 选项卡中观察请求”是什么意思?
  • 谢谢,但是您发送的是js和png文件。那不会有帮助的。网络选项卡是指您的 chrome 或 Firefox 的网络选项卡。能否请您保持打开状态 - 单击保留日志 - 并单击您需要的按钮。观察请求,然后在此处发送这些请求。请记住,在使用请求时——无论是一个 java 按钮还是一个链接——在大多数情况下——您不需要查看 html,您所需要的只是网络选项卡,它可以帮助我们导航。一旦你有这些信息,请用我的名字评论,谢谢
  • @Md-Mohsin。我希望我正确地遵循了您的指示:在 Chrome 中激活了 FN12;网络选项卡、保留日志和红色记录按钮。我不确定是否有我可以在此处发送给您的带有日志的文件。我观察到的是,我输入密码的第一次点击使用的是 POST 方法;之后,当我单击网站中的下一步按钮时,它是一个 GET 方法。我不确定如何发送请求。感谢您继续努力。
  • 能否请您发送 2 个请求的屏幕截图。 #1 您使用发布和登录的那个 #2 当您单击 java 按钮时,您所说的获取请求。您必须使用会话来一个接一个地继续。

标签: javascript python button python-requests


【解决方案1】:

感谢@Md-Mohsin 的建议和推动,我使用 Chrome FN12 的“网络”选项卡记录了会话,保留日志。我发现,在登录授权后,我应该输入一个带有目标的 URL。 我用于 requests.Session().get 的 URL 参数是

https://gj3s.inklingmarkets.com/ + something else

上面的 URL 应该作为目标参数在不同的更长的 URL 中传递

https://www.goodjudgmentproject.com/forecasting/pm_redir.php?target=https://gj3s.inklingmarkets.com/user/good_judgment_authentication?u=

记录的日志显示了所有地址,在 POST 和 GET 操作中登录。我找到了我在上面粘贴的那个。我想这就是 JavaScript 所做的。所以现在我分两步访问网站的代码是

user= 'my_e-mail_address@gmail.com'; pw = 'my_password'
Log_URL= 'https://www.goodjudgmentproject.com/forecasting/login.php'
Welcome_URL= 'https://www.goodjudgmentproject.com/forecasting/pm_redir.php?target=https://gj3s.inklingmarkets.com/user/good_judgment_authentication?u='
s = requests.Session()
r = s.post(Log_URL, data={"email":user, "password":pw})
r = s.get(Welcome_URL)

【讨论】:

    猜你喜欢
    • 2016-11-01
    • 1970-01-01
    • 2018-08-07
    • 2021-03-18
    • 1970-01-01
    • 1970-01-01
    • 2019-05-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多