Recent

Author Topic: How to login to website using internettools?  (Read 6238 times)

Matt723

  • New Member
  • *
  • Posts: 20
How to login to website using internettools?
« on: December 13, 2019, 04:42:31 pm »
Hello,

I'm trying to login to an HTTPS website using internettools. I've had a look at the documentation (https://wiki.freepascal.org/Internet_Tools#Load_a_web_page:) tried the following, but I still can't get it to work:

Code: Pascal  [Select][+][-]
  1. httpRequest(process('https://www.website.com/', form("login": LabeledEdit1.Text, "password": LabeledEdit2.Text)));

Does anybody have any experience with this project and knows a solution?

Thanks for your help.

Matt723

  • New Member
  • *
  • Posts: 20
Re: How to login to website using internettools?
« Reply #1 on: December 14, 2019, 01:30:09 pm »
On the website, here are the fields that I'm trying to fill out:

Code: Text  [Select][+][-]
  1. <dd><input type="text" name="login" id="LoginControl" class="textCtrl" tabindex="143" /></dd>
Code: Text  [Select][+][-]
  1. <input type="password" name="password" class="textCtrl" id="ctrl_password" tabindex="156" />

After searching the forum for different posts relating to this topic, I found this example:

Code: Pascal  [Select][+][-]
  1. httpRequest(process('...portal.asp?', 'form((//form)[1], {"userid": "me", "pwd": "password"})'))

So, changing this to what I need, I'd get (replacing my actual password with #s):

Code: Pascal  [Select][+][-]
  1. httpRequest(process('https://www.mywebsite.com/, 'form((//form)[1], {"login": "MyUsername", "password": "#####"})'))

But I don't understand what the form((//form)[1], means? What does this mean and where can I find the "form" in a website's source?

Thanks.

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: How to login to website using internettools?
« Reply #2 on: December 14, 2019, 01:45:37 pm »
Tell us the website you're trying to login, else we can't say how to, each site is different...

Matt723

  • New Member
  • *
  • Posts: 20
Re: How to login to website using internettools?
« Reply #3 on: December 14, 2019, 05:50:20 pm »
Tell us the website you're trying to login, else we can't say how to, each site is different...
I can't say which website I'm trying to log into. But if you tell me what you think form((//form)[1], might mean, I might be able to see how to apply this code snippet to my project. Thanks for your time.

Matt723

  • New Member
  • *
  • Posts: 20
Re: How to login to website using internettools?
« Reply #4 on: December 14, 2019, 06:15:13 pm »
It is a XenForo forum that's exactly like this one I found: http://jpicforum.info/ The login page is here: http://jpicforum.info/login

Thanks!!

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: How to login to website using internettools?
« Reply #5 on: December 14, 2019, 08:02:47 pm »
The form id is 'pageLogin', the mail is 'login', the password is 'password'.

I never used internettools, but maybe is querying the first form in the html tree, maybe you can tell it to query the form by id sending to it pageLogin instead of a number. But is just a guess.

Code: Text  [Select][+][-]
  1. <form action="login/login" method="post" class="xenForm formOverlay" id="pageLogin">
  2.  
  3.        
  4.        
  5.         <h2 class="textHeading">Log In or Sign Up...</h2>
  6.  
  7.         <dl class="ctrlUnit">
  8.                 <dt><label for="ctrl_pageLogin_login">Your name or email address:</label></dt>
  9.                 <dd><input type="text" name="login" value="" id="ctrl_pageLogin_login" class="textCtrl"></dd>
  10.         </dl>
  11.  
  12.  
  13.         <dl class="ctrlUnit">
  14.                 <dt><label for="ctrl_pageLogin_password">Do you already have an account?</label></dt>
  15.                 <dd>
  16.                         <ul>
  17.                                 <li><label for="ctrl_pageLogin_not_registered"><input type="radio" name="register" value="1" id="ctrl_pageLogin_not_registered">
  18.                                         No, create an account now.</label></li>
  19.                                 <li><label for="ctrl_pageLogin_registered"><input type="radio" name="register" value="0" id="ctrl_pageLogin_registered" checked="checked" class="Disabler">
  20.                                         Yes, my password is:</label></li>
  21.                                 <li id="ctrl_pageLogin_registered_Disabler">
  22.                                         <input type="password" name="password" class="textCtrl" id="ctrl_pageLogin_password">                                  
  23.                                         <div><label for="ctrl_pageLogin_remember" class="rememberPassword"><input type="checkbox" name="remember" value="1" checked="checked" id="ctrl_pageLogin_remember"> Stay logged in</label></div>
  24.                                 </li>
  25.                         </ul>
  26.                 </dd>
  27.         </dl>
  28.  
  29.        
  30.        
  31.  
  32.         <dl class="ctrlUnit submitUnit">
  33.                 <dt></dt>
  34.                 <dd>
  35.                         <input type="submit" class="button primary" value="Log in" data-loginphrase="Log in" data-signupphrase="Sign Up">
  36.                         <a href="lost-password/" class="OverlayTrigger OverlayCloser">Forgot your password?</a>
  37.                 </dd>
  38.         </dl>
  39.  
  40.        
  41.  
  42. <dl class="ctrlUnit">
  43.        
  44.                 <dt></dt>
  45.                 <dd><a href="register/facebook?reg=1" class="fbLogin"><span>Login with Facebook</span></a></dd>
  46.        
  47.        
  48.                 <dt></dt>
  49.                 <dd><a href="register/twitter?reg=1" class="twitterLogin"><span>Login with Twitter</span></a></dd>
  50.        
  51.        
  52.        
  53.                 <dt></dt>
  54.                 <dd><a href="register/google?reg=1" class="googleLogin"><span>Login with Google</span></a></dd>
  55.        
  56. </dl>
  57.        
  58.         <input type="hidden" name="cookie_check" value="1">
  59.         <input type="hidden" name="redirect" value="forum/">
  60.         <input type="hidden" name="_xfToken" value="">
  61.  
  62. </form>

Matt723

  • New Member
  • *
  • Posts: 20
Re: How to login to website using internettools?
« Reply #6 on: December 14, 2019, 09:56:56 pm »
Thanks for that Lainz. So I've got this now:

Code: Pascal  [Select][+][-]
  1. httpRequest(process('http://jpicforum.info/login', form(pageLogin, "login": "example@gmail.com", "password": "password123")))

But this still does not work.

I had a look at the functions httpRequest:

Code: Pascal  [Select][+][-]
  1. //**Make a HTTP GET request to a certain url.
  2. function httpRequest(url: string): string; overload;
  3. //**Make a HTTP POST request to a certain url, sending the data in rawpostdata unmodified to the server.
  4. function httpRequest(url: string; rawpostdata: string): string; overload;
  5. //**Make a HTTP POST request to a certain url, sending the data in postdata to the server, after url encoding all name=value pairs of it.
  6. function httpRequest(url: string; postdata: TStringList): string; overload;
  7. //**Make a HTTP request to a certain url, sending the data in rawdata unmodified to the server.
  8. function httpRequest(const method, url, rawdata: string): string; overload;      

Do you think the syntax is right in my code?

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: How to login to website using internettools?
« Reply #7 on: December 14, 2019, 10:20:32 pm »
From the Free Pascal - General mailing list in 2013:

Quote
My Internet Tools (http://www.benibela.de/sources_en.html#internettools) are made for that.

For example:

Code: Pascal  [Select][+][-]
  1. uses simpleinternet;
  2.  
  3. var i: IXQValue;
  4. begin
  5.   for i in process(httpRequest(process('http://www.example.org/the/page/with/the/login/form', 'form(/form, {"username": "'+username+'", "password": "'+password+'"})')),
  6.                    '//tr/td[2]') do
  7.     writeln(i.toString);
  8. end.
  9.  

will fill out the login form on the first page, then load the second page, and print the values of the second column of all table rows.

 

TinyPortal © 2005-2018