Jump to content

Get HTML Page


Go to solution Solved by mikell,

Recommended Posts

I've been trying to capture the output of the nccs.php file using Curl, but I cannot get it to work correctly. First here's my Autoit code. (Note: I have double checked that $sDate is correctly formatted):

;Set path to Curl
    $sPath = EnvGet ('PATH')
    $sPath = $sPath & ';C:\utility\Curl\bin\'
    EnvSet ('PATH', $sPath)

; Run Curl
    $cmd = 'curl.exe -u username:password https://instanthousecall.com/x/admin/nccs.php?startDate=$sDate$'
    $iPID = Run('$cmd$', "C:\utility\Curl\bin\", @SW_HIDE, $STDOUT_CHILD)
    ProcessWaitClose($iPID)
    $sHTML = StdoutRead($iPID)
    MsgBox (262144, '', $sHTML)

Here's the display of MsgBox  showing the @sHTML varaible on the last line:

MessageBox.png.6fb38a0b11cdd543bc2863be6fd52a94.png

 

Now if I open a Command Window and change to the directory where Curl.exe is, and then run the exact same command line this is what I get:

CommandLine.thumb.png.6d75767b2dbee97c0b5e2bb2ce9ca4c9.png

Note the text after "/head" in the  command window. That is the text that I need to see in the Autoit script.

I feel like I'm very close, but I can't figure out why it only works in the command window.

Any help would be greatly appreciated!

Thanks, John

 

Edited by major4579
Link to comment
Share on other sites

From the help file --

Quote

StdoutRead() does not block, it will return immediately. In order to get all data, it must be called in a loop.

Have you tried reading the output in a loop? --

Local $sOutput = ""
        While 1
                $sOutput &= StdoutRead($iPID)
                If @error Then ; Exit the loop if the process closes or StdoutRead returns an error.
                        ExitLoop
                EndIf
        WEnd
        
        MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput)

 

Link to comment
Share on other sites

Hi @major4579,

in case the suggested way of @Danp2 doesn't work for you, you could also work-around it by transfer the cURL response to a file and then read this [...] proceed it. I know this would not very elegant, but it should work at least.

Something like this:

$cmd      = 'curl.exe -u username:password https://instanthousecall.com/x/admin/nccs.php?startDate=$sDate$'
$filePath = @ScriptDir & '\response.txt'
$iPID     = Run('$cmd$ > "' & $filePath & '"', "C:\utility\Curl\bin\", @SW_HIDE, $STDOUT_CHILD)

Best regards
Sven

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

45 minutes ago, major4579 said:

I tried that but it did not work  any differently then "ProcessWaitClose($iPID)"

To clarify, my suggestion was to use the loop following the ProcessWaitClose, not as a replacement for it. Do it this way will eliminate the chance that only a portion of the output is captured.

Link to comment
Share on other sites

@SOLVE-SMART

It's doing the same thing.

If I run

C:\utility\Curl\bin\curl.exe -u username:passwordhttps://instanthousecall.com/x/admin/nccs.php?startDate=2023-01-11 > D:\IHC.txt

In a command window (does not matter what location I'm running it from) i works fine D:\IHC.txt contains what I need.

If I run the exact same line in Autoit, D:\IHC.txt never even gets created.

$cmd = 'C:\utility\Curl\bin\curl.exe -u username:password https://instanthousecall.com/x/admin/nccs.php?startDate=2023-01-11 > D:\IHC.txt'

$iPID = Run('$cmd$', 'C:\utility\Curl\bin', @SW_HIDE)

But if I run 

$cmd = 'C:\utility\Curl\bin\curl.exe -u username:password https://instanthousecall.com/x/admin/nccs.php?startDate=2023-01-11 > D:\IHC.txt'

$iPID = Run($cmd, 'C:\utility\Curl\bin', @SW_HIDE)

It does work. For what it's worth I do have "Opt ("ExpandVarStrings", 1)  " at the beginning of my autoit file.

Link to comment
Share on other sites

Finally, This code works:

$cmd = 'C:\utility\Curl\bin\curl.exe -u username:password https://instanthousecall.com/x/admin/nccs.php?startDate=' & $sDate

$iPID = Run($cmd, 'C:\utility\Curl\bin', @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($iPID)
$sHTML = StdoutRead($iPID)

Previously in the $cmd line I had $sDate in the end of the string as $sDate$ and in the Run command I had '$cmd$'. But for some reason I haven't figured out the Opt ("ExpandVarStrings", 1)  had stopped working . Interestingly it works everywhere else as far as I can see. In fact if I add MsgBox (262144, '', '>>>$sHTML$<<<') after the last line above that works correctly!

Go figure.

Thanks to both Danp2 and SOLVE-SMART for sticking with me while we figured this out.

BTW, who should get the credit?

John

Link to comment
Share on other sites

30 minutes ago, major4579 said:

Finally, This code works [...]

Nice 😀 .

 

7 minutes ago, Danp2 said:

[...] You should give credit to @mikellsince using curl was his idea.

Agreed 👍 .

A last tryout could be the usage of ShellExecute() instead of Run(). Just to ensure the bahavior is the same or not.

Best regards
Sven

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

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...