How to print the third instance of an attribute using Cheerio JS - node.js

There is 3 instances of 'authenticity_token' in this html:
<form class="edit_checkout" action="/942252/checkouts/624527ae778897e534d917b52af2eb28" accept-charset="UTF-8" method="post"><input type="hidden" name="_method" value="patch" /><input type="hidden" name="authenticity_token" value="5vK3h2ocwaKm0hZ+AH3HAtnffe9l7hQHIMDfrMPusFhxtSV6IbLBfWOnBboOBysF7NyDPQ7GNxdfcWUPOk5WSQ==" />
<form class="edit_checkout" action="/942252/checkouts/624527ae778897e534d917b52af2eb28" accept-charset="UTF-8" method="post"><input type="hidden" name="_method" value="patch" /><input type="hidden" name="authenticity_token" value="Fkw7j/Wv0Xxhna1aWNh8FsZhNnXz4zu0vFuTV0q9WJ6BC6lyvgHRo6Tovp5WopAR82LIp5jLGKTD6in0sx2+jw==" />
<form class="edit_checkout" data-payment-form="" action="/942252/checkouts/624527ae778897e534d917b52af2eb28" accept-charset="UTF-8" method="post"><input type="hidden" name="_method" value="patch" /><input type="hidden" name="authenticity_token" value="Bs1PNacx4rK5TJcl+VDO+RXnR69DixOH+osJ/yxuQQeRit3I7J/ibXw5hOH3KiL+IOS5fSijMJeFOrNc1c6nFg==" />
The actual token (the value I want) is the value attribute and in this case I want the 3rd instance of 'authenticity_token'.
All 3 instances start with <form class="edit_checkout" but the third is followed by data-payment-form="" instead of action="/ . so I know the one I want is the one that includes data-payment-form
I tried using this code in Cheerio:
$('form.edit_checkout input['name="authenticity_token"']')
But that returns the first auth token on the first line and I need the auth token on the third line.
Thanks!

How about:
let input = $('[name="authenticity_token"]')[2]
Then to get the value:
let value = $(input).attr('value')

Related

Some html tags are missing when i write to a file using python requests

I am trying to login to a website using requests.The website requies token for its login.
so decided to parse the html and write it to a file.txt But the file.txt is missing the token tag.
HTML code:
<form id="pw_form" class="exception_password" action="/409514769/password" method="post" data-xsrf-protection="enabled">
<input type="password" id="password" class="exception_password-input iris_input" name="password" placeholder="Enter password" autocomplete="off" data-validators="required">
<input type="hidden" name="is_review" value="">
<input type="hidden" name="is_file_transfer" value="">
<input type="submit" value="Submit" class="iris_btn iris_btn--primary">
<input type="hidden" name="token" value="4dc82c1a780e11667650f856da9b1d9fd31b176b.e7mu8nmqrb.1587446534"></form>
PYTHON code:
from requests import Session
with Session() as s:
site = s.get("https://vimeo.com/409")
with open('page.txt','w') as out:
out.write(site.text)
This is what the file writes:
<form id="pw_form" class="exception_password" action="/409514769/password" method="post">
<input type="password" id="password" class="exception_password-input iris_input" name="password" placeholder="Enter password" class="password iris_form_text" autocomplete="off" data-validators="required">
<input type="hidden" name="is_review" value="">
<input type="hidden" name="is_file_transfer" value="">
<input type="submit" value="Submit" class="iris_btn iris_btn--primary">
</form>
What is happening here?
Website don't allow request from bot.
One possible solution to this problem is to add headers while making the request.

Get more than one GET argument on ESP8266 Asynch Webserver

I would like to build a tiny webserver application for my ESP8266.
If i send the GET request from my browser to the ESP8266 Server, i can only receive one argument.
Here is the code for my sending procedure:
<form method="get" action="/get">
<fieldset>
<legend>Select Pumps</legend>
<input type="checkbox" name="message" value="1">Pump 1<br>
<input type="checkbox" name="message" value="2">Pump 2<br>
<input type="checkbox" name="message" value="3">Pump 3<br>
<input type="checkbox" name="message" value="4">Pump 4<br>
<input type="checkbox" name="message" value="5">Pump 5<br>
<input type="checkbox" name="message" value="6">Pump 6<br>
<input type="checkbox" name="message" value="7">Pump 7<br>
<input type="checkbox" name="message" value="8">Pump 8<br>
<br>
<input type="submit" value="Start waterring!" />
</fieldset>
When the form has been sent, the server should give me back all arguments of the get request but it returns only the first argument
Hello, GET: 3
/get?message=3&message=4
Here is the actual code for processing the request:
// Send a GET request to <IP>/get?message=<message>
server.on("/get", HTTP_GET, [] (AsyncWebServerRequest *request) {
String message;
if (request->hasParam(PARAM_MESSAGE)) {
message = request->getParam(PARAM_MESSAGE)->value();
} else {
message = "No message sent";
}
request->send(200, "text/plain", "Hello, GET: " + message);
});
I'm quite a newbie in programming webservers on microcontrollers and would appreciate any help :)
If you are using this: https://github.com/me-no-dev/ESPAsyncWebServer#request-variables there is actually solution there. You don't have to use names but you can validate them if that's required. Check section: GET, POST and FILE parameters.
int params = request->params();
for(int i=0;i<params;i++){
AsyncWebParameter* p = request->getParam(i);
...
}

Pay pal form post Modify payment amount while submitting

I have a used Paypal Html form post for my eCommerce site.
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target='_new' id='paypalForm'>
<input name="currency_code" type="hidden" value="<?php echo "EUR"; ?>" />
<input name="shipping" type="hidden" value="<?php echo "00.00"; ?>" />
<input name="tax" type="hidden" value="00.20" />
<input name="return" type="hidden" value="<?php echo "http://www.web.com/login.php"; ?>" />
<input name="cancel_return" type="hidden" value="<?php echo "http://www.web.com/cancel.php"; ?>" />
<input name="notify_url" type="hidden" value="<?php echo "http://www.web.com/ipn.php"; ?>" />
<input name="cmd" type="hidden" value="_xclick" />
<input name="business" type="hidden" value="<?php echo "XXXXXXXXXXX"; ?>" />
<input name="item_name" type="hidden" value="camp" />
<input name="no_note" type="hidden" value="1" />
<input name="lc" type="hidden" value="EN" />
<input name="bn" type="hidden" value="PP-BuyNowBF" />
<input name="amount" type="hidden" value="100" />
</form>
And the Javascript
var form = $("form");
form.submit();
I have found that by triggering a form submit function in console, I am able to update the amount that is passed to the Paypal payment process. So, Anyone can do the same right. Is there a secure way to do the payment process using form post in Paypal
Yes, instead of using plain text button (like the one used in your example), use hosted button.
When you use hosted button all the information is store on PayPal side. You just need to pass hosted button id in form.
See if the following link helps:
https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/buy_now_step_1/

Send single String/not Object with Thymeleaf to Spring

I'm trying to send a single String to my Spring backend. I don't want to make an extra Object just for that string.
<form name="f" th:action="#{/restaurant_SaveLayout}" method="post">
<input type="hidden" value="trdz234"/>
<button type="submit"></button>
</form>
Spring tells me that I the RequestParam is not present.
#PostMapping("/restaurant_SaveLayout")
public String restaurant_SaveLayout (#RequestParam String circles) {
return "restaurant_ShowArr";
}
I also don't want to send anything via GET.
You missed to set the name of the input.
<form name="f" th:action="#{/restaurant_SaveLayout}" method="post">
<input type="hidden" name="circles" value="trdz234"/>
<button type="submit"></button>
</form>

Pyramid ignore missing template variables

I have a simple form using Pyramid and I want to use it as a new or update. I don't particularly want to have to create empty dictionary values for all the fields in my form, I just want it to ignore them without raising an exception.
<div metal:fill-slot="content">
<form method="POST" action="/studentupdate">
<input name="id" value="${studentid}" type="hidden" />
Name: <input type="text" name="studentname" value="${studentname}"/><br />
Exam Score: <input type="text" name="studentexam" value="${studentexam}"/><br />
Quiz Score: <input type="text" name="studentquiz" value="${studentquiz}"/><br />
Homework Score: <input type="text" name="studenthomework" value="${studenthw}"/><br />
<input type="submit" value="Save"/>
</form>
</div>
How can I do this?
Thanks.
You can workaround like this
${studentexam or ''}
% for i in missing_list or []
<li>${i}</li>
% endfor

Resources