Shell: connecting to a website and accessing a field

I want to write a script that takes an argument, which is text, opens a connection to a specific site and enters the argument into a text field using the field identifier. Is it possible? How can I do it? I'm a complete noob shell

Edit:

Accurate flow:

- start script with string - input string into text field on web page - click form button - wait for processing - click hyperlink 
+4
source share
4 answers

If you know exactly which field needs to be filled, this can be done using lynx . Suppose you get an S string using a script as an input argument. Then you create a script command that will guide lynx through its behavior.

For example, suppose S=foo , and your field is the second field on the web page. After that, there are two more fields, and then the submit button. After that, you wait for the page to load and click on the hyperlink (after that you exit). Web page www.something.com.

The script command will be in the bar.txt file:

 key <tab> //get to first field key <tab> //get to second field key f //input f key o //input o key o //input o key <tab> //get to third field key <tab> //get to fourth field key <tab> //get to sumbit button key ^J //click submit and wait for load key <tab> //get to hyperlink key ^J //click hyperlink and wait for load key Q //exit key y //confirm exit 

Then the main command will be lynx www.something.com -accept_all_cookies -cmd_script=bar.txt

Now you only need to dynamically create an input line.

 #!/bin/bash script=bar.txt input=$1 webpage=www.something.com len=${#input} echo 'key <tab>' > $script echo 'key <tab>' >> $script for i in `echo $input|fold -w1` do echo 'key '$i >> $script done echo 'key <tab>' >> $script echo 'key <tab>' >> $script echo 'key <tab>' >> $script echo 'key ^J' >> $script echo 'key <tab>' >> $script echo 'key ^J' >> $script echo 'key Q' >> $script echo 'key y' >> $script lnyx $webpage -accept_all_cookies -cmd_script=bar.txt 

Now all you have to do is save the script, change it as executable and call it ./script your_string

+4
source

To get started, here is my script to order lunch from our local dining room today:

 URL="https://lunch.com/lunch/cgi-bin/order.cgi" O="order=Order" A="amount_%d=%%d&amount_foil_container_%d=%%d" function order_lunch() { if [[ -n " $@ " ]]; then curl -u "$USER":"$PASSWORD" \ -d $(printf $(printf "$O&$A&$A&$A&$A" 0 0 1 1 2 2 3 3) \ "${@:2:8}") \ "$URL"; else echo "Nothing to order."; fi; } 

If the input is a string in the following format

 2012-08-23 1 0 0 0 0 0 0 0 

where each field denotes a different dish, that is, 1 in the first position after the date "1 pasta"

Good luck.

+3
source

... "opens a connection to a specific website and enters an argument into the text field using the field identifier" ...

You want you to fill out and submit the HTML <form> ... </form> , right?

I would use curl (http://curl.haxx.se/). With curl, you can easily automate HTTP POST requests, suppose you have a website with the following form (excerpt from: http://curl.haxx.se/docs/httpscripting.html ):

 <form method="POST" action="junk.cgi"> <input type=text name="birthyear"> <input type=submit name=press value=" OK "> </form> 

this command will fill out and submit the form (let it pretend that the form is available at http://www.example.com/when.cgi ):

 curl --data "birthyear=1905&press=%20OK%20" http://www.example.com/when.cgi 
+1
source

I think you need to grab the forms first before trying to do this.

The point is that you can play the thml file locally, which includes all the values ​​of the form, the action of the forms can be the final URLs of steps 3 and 4, and also view the automatic sending of java scripts

The final hyperlink is best after submitting the form - if the last step is by analyzing the outcome of the message and then using curl or wget or something that will act as a click

The E2A problem with the bash script is that my concept above for creating a form is bullish shit, because for executing a java script command line browser or links / lynx / wget / curl, etc. will be a problem

The first question is whether the form supports both get and post - if the form’s action can only be a message, you won’t be able to submit form fields as variables ie

http://destinatio-form-url.com/acceptform.cgi?user=something&address=something_else

This example above is how you can generate form values, if get is supported, if you need to send a message, then it is necessary that the form be completed using the form action set for publishing in order to go to that URL, and this looks like what I said you need to create the form.

If we assume that you can send it through the above format, then the thing you need to pay attention to is where the answer is in the clickable link, if it is just another click - you can see the problem if, however, it returns to that on the same page, it's pretty easy to parse html using grepping for something specific and grepping / awking until you get the exact url that you are running,

take a look at my answer here

bash script to enter web page

Here is how you could do Java authentication by grabbing cookies and then moving forward as a registered user, that is all you need to publish your form

All that I can say is possible in bash, but URL processing can be done in a more suitable language, which gives you all the libraries for this and makes it more elegant than calling all kinds of system commands.

The above example is presented in Java, but can be in any language, perl, php, python, etc., and all of them must have libraries for this task, since Perl looks for LWP html in google and many specific libraries, such as LWP HTML Parser etc. You could use

Anyway the best

I think links support java scripts if that helps.

this is similar to lynx but has much more extras

  apt-cache search links|grep browser amule-gnome-support - ed2k links handling support for GNOME web browsers elinks - advanced text-mode WWW browser elinks-data - advanced text-mode WWW browser - data files elinks-doc - advanced text-mode WWW browser - documentation elinks-lite - advanced text-mode WWW browser - lightweight version libhtmlunit-core-js-java - GUI-Less browser for Java programs - JavaScript engine libhtmlunit-java - GUI-Less browser for Java programs libjenkins-htmlunit-java - Jenkins branch of HtmlUnit browser testing for web apps libphp-snoopy - Snoopy is a PHP class that simulates a web browser links - Web browser running in text mode links2 - Web browser running in both graphics and text mode man2html - browse man pages in your web browser surf - simple web browser 
0
source

Source: https://habr.com/ru/post/1433763/


All Articles