header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Login to a forum
Last Post 13 Feb 2008 11:57 AM by pjo. 7 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
pjoUser is Offline
New Member
New Member
Posts:7
Avatar

--
04 Feb 2008 01:45 PM  

Hi! I am trying to write a PowerShell script to login to a forum.

$wc = new-object system.net.webclient
$wc.credentials = new-object system.net.networkcredential("username", "password";)
$wc.DownloadFile(" http://www.forex-tsd.com/", "d:\work\index.html";)

This does not work.

I found:

http://scriptolog.blogspot.com/2007/01/automated-web-forms.html

Pls advise how to adopt this to login to http://www.forex-tsd.com .

Thanks in advance.

pjo

 

 

 

smurawskiUser is Offline
New Member
New Member
Posts:46

--
04 Feb 2008 02:08 PM  
pjo,

To modify Shay's function for your forum, you will need to look at the page source for your forum login screen. You can replace the "Email" with whatever the ID defines the box where you put your username in this line $ie.document.getElementById("Email").value=$uname.

Same with the password line.

I would also change the function name and default URL, to something like this:

function Login-Forex{
param(
[string]$uname,
[string]$url="http://www.forex-tsd",
[bool]$cookie=$FALSE
)

$creds = get-credential $uname
$pass = $creds.GetNetworkCredential().Password
$ie=new-object -com internetexplorer.application
$ie.visible=$TRUE
$ie.navigate($url)
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.document.getElementById("vb_login_username").value=$uname
$ie.document.getElementById("vb_login_password").value = $pass
$ie.document.getElementsByName("PersistentCookie") | foreach {$_.checked=$cookie}
$ie.document.getElementById("Log In").submit()
}

I don't have an account on those forums, so I can't check if it works, but give it a try.
Steven Murawski
Co-Host - Mind of Root (www.mindofroot.com)
Host - PowerShell Basics (powershell-basics.com)
pjoUser is Offline
New Member
New Member
Posts:7
Avatar

--
09 Feb 2008 12:58 AM  

Posted By smurawski on 02/04/2008 6:08 AM
pjo,

To modify Shay's function for your forum, you will need to look at the page source for your forum login screen. You can replace the "Email" with whatever the ID defines the box where you put your username in this line $ie.document.getElementById("Email").value=$uname.

Same with the password line.

I would also change the function name and default URL, to something like this:

function Login-Forex{
param(
[string]$uname,
[string]$url="http://www.forex-tsd",
[bool]$cookie=$FALSE
)

$creds = get-credential $uname
$pass = $creds.GetNetworkCredential().Password
$ie=new-object -com internetexplorer.application
$ie.visible=$TRUE
$ie.navigate($url)
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.document.getElementById("vb_login_username").value=$uname
$ie.document.getElementById("vb_login_password").value = $pass
$ie.document.getElementsByName("PersistentCookie") | foreach {$_.checked=$cookie}
$ie.document.getElementById("Log In").submit()
}

I don't have an account on those forums, so I can't check if it works, but give it a try.

 

Thanks for your reply.

 

I modified it as follows:

function Login-Forex{
param(
[string]$uname,
[string]$url="http://www.forex-tsd.com",
[bool]$cookie=$FALSE
)

$creds = get-credential $uname
$pass = $creds.GetNetworkCredential().Password
$ie=new-object -com internetexplorer.application
$ie.visible=$TRUE
$ie.navigate($url)
while($ie.ReadyState -ne 4) {start-sleep -m 100}
Start-Sleep -Seconds 5
$ie.document.getElementById("navbar_username").value = $unane
$ie.document.getElementById("navbar_password").value = $pass
# $ie.document.getElementsByName("PersistentCookie") | foreach {$_.checked=$cookie}
$forms = @($ie.Document.forms | where {$_.action -match "do=login"})
Start-Sleep -Seconds 5
# $ie.document.getElementById("Log In").submit()
$forms[0].submit()
}

Login-Forex

 

But username cannot be submitted.

What mistake did I make ?

You could register to this forum for free if you would like to.

Thanks again.

pjo

 

 

 

pjoUser is Offline
New Member
New Member
Posts:7
Avatar

--
09 Feb 2008 01:03 AM  

Related question:

 

This is another version:

 $url = " http://www.forex-tsd.com/expert-analysis/801-weekly-winners.html"
# $url = " http://www.forex-tsd.com/indicators-metatrader-4/"
$user = "username"
$pass = "passwordi"

$ie=new-object -com internetexplorer.application
$ie.visible=$true
$ie.navigate($url)

# wait for the page to load completely
# while($ie.ReadyState -ne 4) {start-sleep -m 1000} 
while($ie.busy) {start-sleep 1}
  

# update the values of the login form (the one on the upper right hand side)
Start-Sleep -Seconds 10
$ie.document.getElementById("navbar_username").value=$user
$ie.document.getElementById("navbar_password").value=$pass

# there are at list 7 forms on this page, you need the one
# where "do=login" appears in its action property
# $forms array contains all the forms in the page
# piping it to where-object to filter all that match "do=login"
# and submitting the first one
Start-Sleep -Seconds 10
$forms = @($ie.Document.forms | where {$_.action -match "do=login"})
Start-Sleep -Seconds 10
$forms[0].submit()

# wait for the page to load completely
#while($ie.ReadyState -ne 4) {start-sleep -m 1000}
while($ie.busy) {start-sleep 1}

# you're in
Start-Sleep -Seconds 10
$last = @($ie.document.getElementsByTagName("A")) | where {$_.innerText -eq 'Last »'}
while($ie.busy) {start-sleep 1}
Start-Sleep -Seconds 10
$ie.navigate($last[0].href)
# $ie.navigate($last.href)
# while($ie.ReadyState -ne 4) {start-sleep -m 1000}
 while($ie.busy) {start-sleep 1}

# last page loaded

 

This let me login to a private nonfree forum.

http://www.forex-tsd.com/indicators-metatrader-4/ is a free public forum.

Strange phenomena is that if above Start-sleep statements are deleted, no success to login on Vista.

What would be the cause of this ?

Does it indicate that loading the page is just taking a long time ?

 

pjo

 

 

pjoUser is Offline
New Member
New Member
Posts:7
Avatar

--
09 Feb 2008 01:24 AM  

The next step is to perform some string prossesing:

After loading the $ie,

browse to the last page of that forum.

Then,

Select-String the loaded $ie for a string AAABBB.

And I am in trouble there.

I tried

$wc = New-Object System.Net.WebClient

$wc.DownloadString($ie) > d:\work\test.html
$d = $ie.document.body.innerhtml

$a = Select-String -Path d:\work\test.html -pattern " EURUSD:
"
 $a[-1].ToString().Split(":")

 

$wc.DownloadString("http://www.google.com") is fine, I think.

How should be the download statement with $ie ?

 

 

pjoUser is Offline
New Member
New Member
Posts:7
Avatar

--
12 Feb 2008 02:18 AM  
For some reason the navbar_username gets null.

So if navbar_username and navbar_password is null, $user and $pass should be submitted.
How could this be done ?

function Login-Forex{
param(
[string]$uname,
[string]$url="http://www.forex-tsd.com/",
[bool]$cookie=$FALSE
)

$creds = get-credential $uname
$pass = $creds.GetNetworkCredential().Password
$user = $creds.GetNetworkCredential().username
$ie=new-object -com internetexplorer.application
$ie.visible=$FALSE
$ie.navigate($url)
# while($ie.ReadyState -ne 4) {start-sleep -Milliseconds 1}
Start-Sleep -Seconds 5

$ie.document.getElementById("navbar_username").value = $user
$ie.document.getElementById("navbar_password").value = $pass
# $ie.document.getElementsByName("PersistentCookie") | foreach {$_.checked=$cookie}
$forms = @($ie.Document.forms | where {$_.action -match "do=login"})
Start-Sleep -Seconds 5
# $ie.document.getElementById("Log In").submit()
$forms[0].submit()
}

Login-Forex xxxx

This forum is free public registration required forum.

Thanks in advance.

pjo
pjoUser is Offline
New Member
New Member
Posts:7
Avatar

--
12 Feb 2008 04:37 AM  

Hi!

while($ie.ReadyState -ne 4) {start-sleep -Milliseconds 1}

$ie never gets ready while the page is loaded ok.

What would be the cause of this ?

 

pjo

 

 

pjoUser is Offline
New Member
New Member
Posts:7
Avatar

--
13 Feb 2008 11:57 AM  

Hi!

 

I asked the same or related question in the other forum and i got response.

It is Vista/IE7 problem.

Be aware Vista users !  PowerShell on Vista does not run correctly regarding IE7.

http://www.systemscript.com/forumps1us/forum_posts.asp?TID=16&PID=58#58

 

http://www.systemscript.com/forumps1us/forum_posts.asp?TID=17&PID=59#59

 

pjo

 

 

 

 

You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer