Skip to content
TORNLIFE More

Powershell

Started by Mat-Senpai [952164] on in Technology.

4 replies · 57 views · thread synced · 5 days ago · View on torn.com
About this thread

Posts archived: 5 / 5 posts (100%) · the total is Torn's reply count + the opening post at the last fetch

Counted by TornLife from the archived posts.

Archived posts
5
Discussion span
→
People posting
2
Likes on archived posts
0
Authority score
6 / 100
Historical score
10 / 100
Story score
22 / 100
Engagement score
39 / 100
Mat-Senpai [952164]

Hello

I'm pretty new to powershell but i've been messing around with it for a bit and wanted to ask for some advice, right now i'm looking to do some of my own datamining (although waiting on admin approval before I fully commit) however i'm having one issue and i wanted to see if someone could help me.

Right now I have simple code in order to pull from a webpage and download locally:

$web = New-Object System.Net.WebClient
$web.DownloadFile("http://www.torn.com/x","C:demox1.html")

I've got it set up to that each instant will be adding a sum because I plan to produce a huge list.

My issue is that I want to pull from webpages you can only view once logged in, is there a way to view information from this game via PS without logging in or the more likely one, is there a way to pull information by logging in via PS?



Mat-Senpai [952164]

Perhaps something like:

$username = "username"
$password = "password"
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$false
$ie.navigate("Url")
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.document.getElementById("username").value= "$username"
$ie.document.getElementById("pass").value = "$password"
$ie.document.getElementById("loginform").submit()
start-sleep 20
$ie.Document.body | Out-File -FilePath c:Demox1.txt
Mauk [1494436]

You could also use cookies directly.

$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession $cookie = New-Object System.Net $cookie.Name = "session"$cookie.Value = "sessionvalue"$cookie.Domain = "domain"$sessions.Add($cookie);Invoke-WebRequest $url -WebSession $session -OutFile $file
Mat-Senpai [952164]

New-Object : Cannot find type [System.Net]: verify that the assembly containing this type is loaded.
At line:3 char:11
+ $cookie = New-Object System.Net
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

The property 'Name' cannot be found on this object. Verify that the property exists and can be set.
At line:5 char:1
+ $cookie.Name = "session"
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound

The property 'Value' cannot be found on this object. Verify that the property exists and can be set.
At line:6 char:1
+ $cookie.Value = "sessionvalue"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound

The property 'Domain' cannot be found on this object. Verify that the property exists and can be set.
At line:7 char:1
+ $cookie.Domain = "domain"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound

You cannot call a method on a null-valued expression.
At line:9 char:1
+ $sessions.Add($cookie);
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Invoke-WebRequest : Cannot validate argument on parameter 'Uri'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At line:11 char:19
+ Invoke-WebRequest $url -WebSession $session -OutFile $fil
+ ~~~~
+ CategoryInfo : InvalidData: (:) [Invoke-WebRequest], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeWebRequestC
ommand

_

I'm going to assume these use .NET modules
Mauk [1494436]

Huh... Torn deleted a word. It was supposed to be System dot Net dot C o o k i e.

And of course you need to fill the $url and $file variables beforehand.