Jump to content
lordsocke

InetRead() freaks around

Recommended Posts

lordsocke

Hey there, I´m using a very simple codeline to download a google search.

This repeats every 3 seconds. Sometimes InetRead() works totally fine and sometimes its just delivering an empty string. 

I´ve been googling a bit around and there are some more guy´s seems to have that problem but nobody really got a solution or a work around. 

$url = ("https://www.google.de/search?q="&$text)
$text =BinaryToString(InetRead($url,16))
FileWrite("text.txt",$text)

 

Share this post


Link to post
Share on other sites
lordsocke
48 minutes ago, Danp2 said:

You'll need to change your code to check the value of @error following the call to InetRead.

Error flag is at 13

Share this post


Link to post
Share on other sites
Danp2

Some discussion here, but it doesn't explain the error.

Similar discussions here.

Even if we don't know the reason for the error, you should still be able to properly retry the command a few times until it works.

Share this post


Link to post
Share on other sites
lordsocke
1 hour ago, Danp2 said:

Some discussion here, but it doesn't explain the error.

Similar discussions here.

Even if we don't know the reason for the error, you should still be able to properly retry the command a few times until it works.

for my script it would be nessecary that is works. Do you know any workaround?

Share this post


Link to post
Share on other sites
Bilgus

Instead use inetget()

Local Const $INET_DOWNLOADBACKGROUND = 1
$text = "google"
$url = ("https://www.google.com/search?q="&$text)
GetPage($url)

Func GetPage($sUrl)
    Local $WdataAvail = Inetget($sUrl, @ScriptDir & "\pagetext.txt", 1, $INET_DOWNLOADBACKGROUND)

    If InetGetInfo ($WdataAvail,2) <> True Then
        for $i = 1 to 30 ;continue for 30 seconds
            Sleep(1000)
            If InetGetInfo ($WdataAvail,2) = True Then
                ExitLoop
            EndIf
        Next
        If InetGetInfo ($WdataAvail,3) <> True Then ;Check for success
            InetClose($WdataAvail)
            Msgbox(0,"Error", "Failed")
            Exit
        EndIf
    EndIf
    InetClose($WdataAvail)
EndFunc

 

  • Like 1

Share this post


Link to post
Share on other sites
lordsocke
2 minutes ago, Bilgus said:

Instead use inetget()

Local Const $INET_DOWNLOADBACKGROUND = 1
$text = "google"
$url = ("https://www.google.com/search?q="&$text)
GetPage($url)

Func GetPage($sUrl)
    Local $WdataAvail = Inetget($sUrl, @ScriptDir & "\pagetext.txt", 1, $INET_DOWNLOADBACKGROUND)

    If InetGetInfo ($WdataAvail,2) <> True Then
        for $i = 1 to 30 ;continue for 30 seconds
            Sleep(1000)
            If InetGetInfo ($WdataAvail,2) = True Then
                ExitLoop
            EndIf
        Next
        If InetGetInfo ($WdataAvail,3) <> True Then ;Check for success
            InetClose($WdataAvail)
            Msgbox(0,"Error", "Failed")
            Exit
        EndIf
    EndIf
    InetClose($WdataAvail)
EndFunc

 

Thanks for that, but I dont think its gonna be fast enough for me... the skript is 0.8sec for now per runtime 

Share this post


Link to post
Share on other sites
Bilgus
Local Const $INET_DOWNLOADBACKGROUND = 1
Local $aRet
Local $aHandles[1000]
Local $iCt = 0
$text = "google"
$url = ("https://www.google.com/search?q="&$text)
GetPage($url)
CloseHandles()
Func GetPage($sUrl)
    Local $WdataAvail = Inetget($sUrl, @ScriptDir & "\pagetext.txt", 1)

    $aRet = InetGetInfo ($WdataAvail)
    If IsArray($aRet) and $aRet[2] <> True Then
        for $i = 1 to 300 ;continue for up to 30 seconds
            $aRet = InetGetInfo ($WdataAvail)
            If $aRet[2] = True Then
                ExitLoop
            EndIf
            Sleep(100)
        Next
        If Not IsArray($aRet) or $aRet[3] <> True Then ;Check for success
            InetClose($WdataAvail)
            Msgbox(0,"Error", "Failed")
            CloseHandles()
            Exit
        EndIf
    EndIf
    $iCt += 1
    $aHandles[$iCt] = $WdataAvail
    if $iCt >= 999 Then CloseHandles()
EndFunc
func CloseHandles()
    for $i = 0 to $iCt
        InetClose($aHandles[$i])
    Next
    $iCt = 0
EndFunc

If you are calling it repeatedly you could do something like this..

probably need to tweak it a bit to get it to its full potential but you get the idea

Share this post


Link to post
Share on other sites
lordsocke
1 minute ago, Bilgus said:
Local Const $INET_DOWNLOADBACKGROUND = 1
Local $aRet
Local $aHandles[1000]
Local $iCt = 0
$text = "google"
$url = ("https://www.google.com/search?q="&$text)
GetPage($url)
CloseHandles()
Func GetPage($sUrl)
    Local $WdataAvail = Inetget($sUrl, @ScriptDir & "\pagetext.txt", 1)

    $aRet = InetGetInfo ($WdataAvail)
    If IsArray($aRet) and $aRet[2] <> True Then
        for $i = 1 to 300 ;continue for up to 30 seconds
            $aRet = InetGetInfo ($WdataAvail)
            If $aRet[2] = True Then
                ExitLoop
            EndIf
            Sleep(100)
        Next
        If Not IsArray($aRet) or $aRet[3] <> True Then ;Check for success
            InetClose($WdataAvail)
            Msgbox(0,"Error", "Failed")
            CloseHandles()
            Exit
        EndIf
    EndIf
    $iCt += 1
    $aHandles[$iCt] = $WdataAvail
    if $iCt >= 999 Then CloseHandles()
EndFunc
func CloseHandles()
    for $i = 0 to $iCt
        InetClose($aHandles[$i])
    Next
    $iCt = 0
EndFunc

If you are calling it repeatedly you could do something like this..

probably need to tweak it a bit to get it to its full potential but you get the idea

looks pretty, thanks a los im going to test tomorrow

Share this post


Link to post
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

×