Jump to content

How to code this powershell?


oemript
 Share

Recommended Posts

  • Moderators

PowerShell's usage when dealing with websites is not that different than AutoIt. This is just a rough example I used for another site, but should get you started:

$username='username' 
$password='password'

$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible= $true
$ie.Navigate("site-name")

while ($ie.Busy -eq $true){Start-Sleep -seconds 1;}   

$usernamefield = $ie.Document.getElementByID('UserName1')
$usernamefield.value = $username

$passwordfield = $ie.Document.getElementByID('Passwd1')
$passwordfield.value = $password

$Link=$ie.Document.getElementsByTagName("input") | where-object {$_.className -eq "continue"}
$Link.click()

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Referring to following coding, I would like to know on how to click Export Button and Download csv file using PowerShell Script.

 

# Download the Excel file 
    $clnt = new-object System.Net.WebClient
    $url = "https://financials.morningstar.com/ratios/r.html?t=0P0001648D&culture=en&platform=sal"
    $file = "C:\folder\abc.csv"
    try {
        $request = [System.Net.WebRequest]::Create($url)
        $request.Method = 'HEAD'
        $response = $request.GetResponse()
        $httpStatus = $response.StatusCode
        $urlIsValid = ($httpStatus -eq 'OK')
        $tryError = $null
        $response.Close()
        
        ???? How to click Export Button and Download csv file ???
        $clnt.DownloadFile($url,$file)
        
    }
    catch [System.Exception] {
        $httpStatus = $null
        $tryError = $_.Exception
        $urlIsValid = $false;
        Write-Host "There was an error downloading $file" 
        $j++
    }

Do you have any suggestions?

Thank you very much for any suggestions (^v^)

Link to comment
Share on other sites

14 minutes ago, JLogan3o13 said:

$Link=$ie.Document.getElementsByTagName("input") | where-object {$_.className -eq "continue"} $Link.click()

Referring to following html coding, I would like to know on how to apply $ie.Document.getElementsByTagName in this situation.

<div class="export_list_financials">
<div class="list_select">
<li id="Li2" class="r_dd1" onclick="showDropdown1(event,this);">
<a class="r_ddh1" id="orderType">Ascending</a><ul style="display: none;"><li>
<a href="javascript:orderChange('asc','Ascending');">Ascending</a></li><li>
<a href="javascript:orderChange('desc','Descending');">Descending</a></li></ul></li></div>
<a class="large_button" href="javascript:exportKeyStat2CSV();">
<span class="csv"></span>
<div>Export</div></a></div>

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

Link to comment
Share on other sites

Referring to following image, I get error and would like to know on what object should be selected before click

# Download the Excel file

    $clnt = new-object System.Net.WebClient
    [Net.ServicePointManager]::SecurityProtocol = 'Tls12'
    $url = "https://financials.morningstar.com/ratios/r.html?t=0P0001648D&culture=en&platform=sal"

        $request = [System.Net.WebRequest]::Create($url)
        $request.Method = 'HEAD'
        $response = $request.GetResponse()
        $httpStatus = $response.StatusCode
        $urlIsValid = ($httpStatus -eq 'OK')
        $tryError = $null
        $response.Close()

    $Link=$ie.Document.getElementsByTagName("large_button") 
    $Link.click()

6886a.png

Do you have any suggestions?

Thanks, to everyone very much for any suggestions (^v^)

 

 

Edited by oemript
Link to comment
Share on other sites

Referring to following html coding, does it require AJax in order to perform download task? Can PowerShell able to execute this event for downloading file? or this is the limitation of PowerShell, because it is not support AJax components.

<div class="export_list_financials">
<div class="list_select">
<li id="Li2" class="r_dd1" onclick="showDropdown1(event,this);">
<a class="r_ddh1" id="orderType">Ascending</a><ul style="display: none;"><li>
<a href="javascript:orderChange('asc','Ascending');">Ascending</a></li><li>
<a href="javascript:orderChange('desc','Descending');">Descending</a></li></ul></li></div>
<a class="large_button" href="javascript:exportKeyStat2CSV();">
<span class="csv"></span>
<div>Export</div></a></div>

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

Link to comment
Share on other sites

  • Moderators

@oemript you have been around long enough to know better than to bump your posts in less than 24 hours. Just because this is the most important thing in the world to you does not mean it is to everyone else. And, as usual, if you're not getting the answers you seek perhaps you're not providing enough information or, as is usually the issue with you, not showing enough of what you have tried on your own.

If you are going to continue to sit around and wait for someone to spoon-feed it to you, at least wait 24 hours before bumping and bothering everyone.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...