Phantomjs - How to populate a form, submit and get the results?

后端 未结 1 849
抹茶落季
抹茶落季 2021-02-14 04:10

I can\'t seem to do a simple form submit.

Below is the code that I did to submit \"Test\" to the Google search form and print out the results.

var url =         


        
相关标签:
1条回答
  • 2021-02-14 04:50

    It isn't sufficient to render a page immediately after "clicking". You have to give the web engine time to make whatever calls are required and execute the resulting JavaScript.

    Consider the following after your call to evaluate:

    window.setTimeout(
      function () {
        page.render( 'google.png' );
        phantom.exit(0);
      },
      5000 // wait 5,000ms (5s)
    );
    

    By the way - the click may or may not work depending on what kind of element it is. If that doesn't work I suggest you search the Internet for how to click on a DIV or whatever type of element it happens to be (there is a technique which involves creating a mouse event).

    0 讨论(0)
提交回复
热议问题