Recent

Author Topic: Internet Tools  (Read 65584 times)

christensen

  • Full Member
  • ***
  • Posts: 127
Re: Internet Tools, now with a functional LINQ-like interface
« Reply #30 on: December 13, 2015, 11:30:45 am »
Thanks it work like a charm, only with radio buttons i have issue, to check if is selected i need to check 3 parameters.

Code: Pascal  [Select][+][-]
  1. Door 1
  2. name="5" value="1" >First
  3. name="5" value="2" checked="checked">Second
  4. name="5" value="3" >Third
  5. name="5" value="4" >Forth

i can only check two parameters, name and value.

how can i set 3?

EDIT:

Solved:
Code: Pascal  [Select][+][-]
  1. page.map('//input[@name="5"][@value="1"]/@checked').toString;

now i'm strugling with sending 'checked' to: name="5" value="1" >First

« Last Edit: December 13, 2015, 12:45:35 pm by christensen »
Lazarus 1.4.4, FPC 2.6.4, Windows 7 64bit, AMD Athlon 7750 black edition, Asus M3N78-CM
Lenovo L540 i7-4702MQ, Windows 10 x64,Lazarus 1.6.2,FPC 3.0

BeniBela

  • Hero Member
  • *****
  • Posts: 906
    • homepage
Re: Internet Tools, now with a functional LINQ-like interface
« Reply #31 on: December 13, 2015, 08:54:31 pm »
Solved:
Code: Pascal  [Select][+][-]
  1. page.map('//input[@name="5"][@value="1"]/@checked').toString;

now i'm strugling with sending 'checked' to: name="5" value="1" >First

Sending? You can use

Code: Pascal  [Select][+][-]
  1. page.map('//input[@checked]').toString;

to find the checked one, and

Code: Pascal  [Select][+][-]
  1. page.map('//input[not(@checked)]').toString;

for all the others

christensen

  • Full Member
  • ***
  • Posts: 127
Re: Internet Tools, now with a functional LINQ-like interface
« Reply #32 on: December 13, 2015, 09:23:15 pm »
Thanks for the quick replay, but not working.
Yes i want to submit the selected radiobutton.

this is my complete html code:
Code: Pascal  [Select][+][-]
  1.  <INPUT TYPE="submit" NAME="button" VALUE="set">
  2.   <input type="radio"   name="5" value="1" >First<br>
  3.   <input type="radio"   name="5" value="2" checked="checked">Second<br>
  4.   <input type="radio"   name="5" value="3" >Third<br>
  5.   <input type="radio"   name="5" value="4" >Forth<br>
  6.  
  7.  
« Last Edit: December 13, 2015, 10:33:41 pm by christensen »
Lazarus 1.4.4, FPC 2.6.4, Windows 7 64bit, AMD Athlon 7750 black edition, Asus M3N78-CM
Lenovo L540 i7-4702MQ, Windows 10 x64,Lazarus 1.6.2,FPC 3.0

BeniBela

  • Hero Member
  • *****
  • Posts: 906
    • homepage
Re: Internet Tools, with a functional LINQ-like interface
« Reply #33 on: December 14, 2015, 11:09:57 pm »
this is my complete html code:
Code: Pascal  [Select][+][-]
  1.  <INPUT TYPE="submit" NAME="button" VALUE="set">
  2.   <input type="radio"   name="5" value="1" >First<br>
  3.   <input type="radio"   name="5" value="2" checked="checked">Second<br>
  4.   <input type="radio"   name="5" value="3" >Third<br>
  5.   <input type="radio"   name="5" value="4" >Forth<br>
  6.  
  7.  

Is that the entire html?

It does not like it.

There seems to be a bug, when mixing text and multiple root elements.

You need at least

this is my complete html code:
Code: Pascal  [Select][+][-]
  1. <html><form>
  2.  <INPUT TYPE="submit" NAME="button" VALUE="set">
  3.   <input type="radio"   name="5" value="1" >First<br>
  4.   <input type="radio"   name="5" value="2" checked="checked">Second<br>
  5.   <input type="radio"   name="5" value="3" >Third<br>
  6.   <input type="radio"   name="5" value="4" >Forth<br>
  7. </form></html>
  8.  

as html or you cannot use //. Better even <html><body><form>. Or use (//input) in the query


With a form you can use the form example from above

Code: [Select]
page.map('form(//form).post').toString
or url instead post if it is a get form...

Manually you could use
Code: [Select]
page.map('//input[@checked]/concat(uri-encode(@name), "=", uri-encode(@value))')

« Last Edit: December 15, 2015, 12:28:20 pm by BeniBela »

christensen

  • Full Member
  • ***
  • Posts: 127
Re: Internet Tools, with a functional LINQ-like interface
« Reply #34 on: December 15, 2015, 04:04:27 pm »
Thanks,

I had read the form with what you gived me earlyer.

Now i want to send the checked radio button and submit the web page with that setting.

ex. now the second radio button is checked, i want to check the first one and submit it. How can i do?

i've tried:

Code: Pascal  [Select][+][-]
  1.  page.map('form(//form, {"5": "1", "checked": "checked", "button": "set"})').retrieve();

with no luck :(
« Last Edit: December 15, 2015, 06:02:44 pm by christensen »
Lazarus 1.4.4, FPC 2.6.4, Windows 7 64bit, AMD Athlon 7750 black edition, Asus M3N78-CM
Lenovo L540 i7-4702MQ, Windows 10 x64,Lazarus 1.6.2,FPC 3.0

BeniBela

  • Hero Member
  • *****
  • Posts: 906
    • homepage
Re: Internet Tools, with a functional LINQ-like interface
« Reply #35 on: December 15, 2015, 06:59:20 pm »

Code: Pascal  [Select][+][-]
  1.  page.map('form(//form, {"5": "1", "checked": "checked", "button": "set"})').retrieve();

Have you tried

Code: Pascal  [Select][+][-]
  1.  page.map('form(//form, {"5": "1", "button": "set"})').retrieve();

christensen

  • Full Member
  • ***
  • Posts: 127
Re: Internet Tools, with a functional LINQ-like interface
« Reply #36 on: December 15, 2015, 08:12:44 pm »
Yes, i've tried but doesn't work :(

ps. how could i get a feedback of submit? a boolean or something what can i use for reference.
« Last Edit: December 15, 2015, 08:57:55 pm by christensen »
Lazarus 1.4.4, FPC 2.6.4, Windows 7 64bit, AMD Athlon 7750 black edition, Asus M3N78-CM
Lenovo L540 i7-4702MQ, Windows 10 x64,Lazarus 1.6.2,FPC 3.0

christensen

  • Full Member
  • ***
  • Posts: 127
Re: Internet Tools, with a functional LINQ-like interface
« Reply #37 on: December 15, 2015, 09:31:53 pm »
this is the link and the variables:

Code: Pascal  [Select][+][-]
  1. http://192.168.0.1/index?button=set&5=2&6=2&7=2&8=2&9=2
Lazarus 1.4.4, FPC 2.6.4, Windows 7 64bit, AMD Athlon 7750 black edition, Asus M3N78-CM
Lenovo L540 i7-4702MQ, Windows 10 x64,Lazarus 1.6.2,FPC 3.0

BeniBela

  • Hero Member
  • *****
  • Posts: 906
    • homepage
Re: Internet Tools, with a functional LINQ-like interface
« Reply #38 on: December 15, 2015, 10:27:21 pm »
Yes, i've tried but doesn't work :(

ps. how could i get a feedback of submit? a boolean or something what can i use for reference.

Retrieve parses the webpage that the servers sends after the form request and returns that. If the HTTP connection fails, it throws an exception.

this is the link and the variables:

Code: Pascal  [Select][+][-]
  1. http://192.168.0.1/index?button=set&5=2&6=2&7=2&8=2&9=2


What is the form from the html?

christensen

  • Full Member
  • ***
  • Posts: 127
Re: Internet Tools, with a functional LINQ-like interface
« Reply #39 on: December 16, 2015, 05:15:16 pm »
Yes is html.
Lazarus 1.4.4, FPC 2.6.4, Windows 7 64bit, AMD Athlon 7750 black edition, Asus M3N78-CM
Lenovo L540 i7-4702MQ, Windows 10 x64,Lazarus 1.6.2,FPC 3.0

BeniBela

  • Hero Member
  • *****
  • Posts: 906
    • homepage
Re: Internet Tools, with a functional LINQ-like interface
« Reply #40 on: December 16, 2015, 06:07:26 pm »
Yeah, but what is the tag?

The <form action="..." method=".." /> ?

christensen

  • Full Member
  • ***
  • Posts: 127
Re: Internet Tools, with a functional LINQ-like interface
« Reply #41 on: December 16, 2015, 07:42:41 pm »
The radio button form is like this:



<FORM ACTION ="/index" METHOD ="get">       
<INPUT TYPE="submit" NAME="button" VALUE="get">       
  <INPUT TYPE="submit" NAME="button" VALUE="set">      
Lazarus 1.4.4, FPC 2.6.4, Windows 7 64bit, AMD Athlon 7750 black edition, Asus M3N78-CM
Lenovo L540 i7-4702MQ, Windows 10 x64,Lazarus 1.6.2,FPC 3.0

BeniBela

  • Hero Member
  • *****
  • Posts: 906
    • homepage
Re: Internet Tools, with a functional LINQ-like interface
« Reply #42 on: December 16, 2015, 10:17:34 pm »
Works here, as it should.

What exactly is your source (query and input)?

christensen

  • Full Member
  • ***
  • Posts: 127
Re: Internet Tools, with a functional LINQ-like interface
« Reply #43 on: December 17, 2015, 04:31:37 pm »
Code: Pascal  [Select][+][-]
  1. procedure Tfrmsave_IO;
  2.  
  3.  var page: IXQValue;
  4.  
  5. begin
  6.  
  7.     page := xqvalue('http://192.168.0.1/index').retrieve();
  8.  
  9.    page.map('form(//form,{"5":"1","6":"1","7":"2","8":"1","9":"1","button":"set"})').retrieve();
  10.  
  11. end;                        

<html>
<HEAD>
<TITLE>My Page</TITLE>
</HEAD>
<BODY>

<FORM ACTION ="/index" METHOD ="get">       
<INPUT TYPE="submit" NAME="button" VALUE="get">       
  <INPUT TYPE="submit" NAME="button" VALUE="set">

  <input type="radio"   name="5" value="1" >First<br>
  <input type="radio"   name="5" value="2" checked="checked">Second<br>
  <input type="radio"   name="5" value="3" >Third<br>
  <input type="radio"   name="5" value="4" >Forth<br>

  <input type="radio"   name="6" value="1" >First<br>
  <input type="radio"   name="6" value="2" checked="checked">Second<br>
  <input type="radio"   name="6" value="3" >Third<br>
  <input type="radio"   name="6" value="4" >Forth<br>

.... so on, i have 5 groups of four radio buttons

</form>
</BODY>
</html>

« Last Edit: December 17, 2015, 04:44:46 pm by christensen »
Lazarus 1.4.4, FPC 2.6.4, Windows 7 64bit, AMD Athlon 7750 black edition, Asus M3N78-CM
Lenovo L540 i7-4702MQ, Windows 10 x64,Lazarus 1.6.2,FPC 3.0

BeniBela

  • Hero Member
  • *****
  • Posts: 906
    • homepage
Re: Internet Tools, with a functional LINQ-like interface
« Reply #44 on: December 17, 2015, 08:17:13 pm »
Code: [Select]
var page: IXQValue;

begin

   page := xqvalue('http://192.168.1.5/xxxx/test.html').retrieve();

  writeln(page.map('form(//form,{"5":"1","6":"1","7":"2","8":"1","9":"1","button":"set"})').debugAsStringWithTypeAnnotation());
  writeln(page.map('form(//form,{"6":"1","7":"2","8":"1","9":"1","button":"set"})').debugAsStringWithTypeAnnotation());


gives

Code: [Select]
object: {method: string: GET, url: string: http://192.168.1.5/test.html?5=1&6=1&7=2&8=1&9=1&button=set}
object: {method: string: GET, url: string: http://192.168.1.5/test.html?5=2&6=1&7=2&8=1&9=1&button=set}

as it should.

Do you get something else?

 

TinyPortal © 2005-2018