doujiang1913 2014-04-04 03:32
浏览 118
已采纳

在Python中发送表单请求

I am trying to simulate a button click in Python on a website, when that button is clicked it adds some stuff to the end of the URL and returns false. If I add the stuff to the end of the URL it takes me to the right place but doesn't register that the button was click which is why I think I need to use the return false part.

Here is the exact code for the button and the button area. I don't know if this is actually doing anything or just setting up the button and waiting for the javascript to actually do the execution.

<div class="contractLink"><button  type="button" value="upgrade to level 3"id="button533e24e4d7c79" class="green build" onclick="window.location.href = 'dorf1.php?a=16&amp;c=fb5ad7'; return false;">
    <div class="button-container addHoverClick">
        <div class="button-background">
            <div class="buttonStart">
                <div class="buttonEnd">
                    <div class="buttonMiddle"></div>
                </div>
            </div>
        </div>
        <div class="button-content">upgrade to level 3</div>
    </div>
</button>

This is where the script is that gets run when the button is clicked. I basically want to simulate the button being clicked through a python script which should go to a different URL and say "it's upgraded" (not literally say "it's upgraded" but make the website think it is and start the upgrading process)

<script type="text/javascript">
    window.addEvent('domready', function()
    {
    if($('button533e24e4d7c79'))
    {
        $('button533e24e4d7c79').addEvent('click', function ()
        {
            window.fireEvent('buttonClicked', [this, {"type":"button","value":"upgrade to level 3","name":"","id":"button533e24e4d7c79","class":"green build","title":"","confirm":"","onclick":"window.location.href = \u0027dorf1.php?a=16\u0026amp;c=fb5ad7\u0027; return false;"}]);
        });
    }
    });
</script>

Any help would be great, thanks for your time.

  • 写回答

1条回答 默认 最新

  • duan89197 2014-04-04 05:24
    关注

    This is an alternative to using Python; this might be useful to those wishing to have a button click simulation without having normal subsequent action take place at the testers discretion.

    Assuming that the id of the button to be simulated is "button533e24e4d7c79", the jQuery library has the trigger method to trigger the click (or any supported event for that matter) of this button:

    $("#button533e24e4d7c79").trigger("click"); // This will mimic the clicking of the button (programmatically) -- requires Jquery
    

    My understanding is that the trigger method will invoke the "click" event and stop at the event handler (i.e., won't follow links, won't continue with form submission, etc.). I haven't fully tested, but that's my understanding.

    If it's desired to fully simulate the button click, jquery.simulate.js library (https://github.com/eduardolundgren/jquery-simulate/blob/master/jquery.simulate.js) provides the simulate method to allow following of links, etc.

    The jQuery learning page at http://learn.jquery.com/events/triggering-event-handlers/ provides the proper explanation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd