Skip to main content

Hi,


i’m strugling with it 3rd day and read many docs about querying with fetch on JS, but seems like my understanding of web stuff is not enough.

I used similar method for fetching from API with JSON, or from simple html site parcing text, but here I can’t achieve desired goal.


Site is a base of clients, sorry but for now I didn’t have approve to disclose real name.


https://search.somelongdomain.com,

reloading to https://search.somelongdomain.com/ClientSearch.php?Accept=Accept


it contains form with “Name”, “LastName” etc, then “Start Date”, “End Date” and two buttons, Search and Reset.

After submitting “start_date”, “end_date” i press Search and have list of Clients registered within this period, 20-50 names for 2-3 days, and that’s my desired result.


output loaded as https://search.somelongdomain.com/NamePick.php, it’s a form with name table and checkbox near each, but that’s ok, i know how to extract my data from any type of text

format is html text, site looks a bit old, it doesn’t suppose to receive/output JSON objects. Authorizing not needed.


When i try to POST the query using remoteFetchAsync, it provides html text answer with empty “Start_Date” and “End_date” fields, and a list of 1000 persons (there are thousands in a base, and site outputs them by pages 1000 persons each). So, it cannot receive my filled dates in correct way.


That’s my script output with 1000 names array



UPD after Solution:

spotted a bug in my ‘pase function’ (for pos1), just in case i’ll need it in future, here is a correct version:


const FINDROW='cursor:pointer' //some tag to divide list of items
const FINDCOL=`value = '` // tag at item start
const ENDSTR=`' name =` // tag at item end

function parseTXT(txt){return txt.split(FINDROW).map(getString).filter(n=>n)}
function getString(text){
let pos1=text.indexOf(FINDCOL)+FINDCOL.length;
if (pos1<=FINDCOL.length) return null;
let pos2=text.indexOf(ENDSTR,pos1);
if (pos2<=0) return null;
return text.slice(pos1,pos2);
}

That’s html code of form and input fields + buttons



I tried text, JSON. Also tried approach with


let formData = new FormData();
formData.append('key1', 'value1');
formData.append('key2', 'value2');

I suppose maybe i need at first extract something from first link,

https://search.somelongdomain.com/ClientSearch.php


like form template etc, then fill it with my values, and then POST it to second link,

https://search.somelongdomain.com/NamePick.php,

but i don’t understand how it works…


or maybe that’s impossible due to some remoteFetchAsync restrictions?

Wow, i don’t know why and how, but it’s worked !


During random chaotic implementing of different solutions, it output the desired result.


I tested and changes are:


used “FormData” approach, but instead,


let fData=new URLSearchParams();
fData.append('key','value').....

second, added redirect parameter


const options={
method:'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
redirect: 'manual',
body: fData,
}

hope this will help somebody 🙂


Reply