Jump to content

Recommended Posts

Posted (edited)

Hi my friends, I wrote a loop to grab from google search some covers, to do that I put inside a loop _IECreate and _IEQuit but some times crash! My opinion is... IE object result opened and when the new loop cicle try to recreate it fail, which is your proof idea to solve it??? THX

#include <String.au3>
#include <ie.au3>
#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=

DirCreate(@ScriptDir&"\img")

$cabinet = "pc"
$type = "jpg"
$width = "800"
$height = "600"

$games = FileReadToArray("C:\Users\rootx\Desktop\lista game pc.txt")

Local $sSource, $aImgURL, $sKeyWord
Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = ""

For $s = 1 to UBound($games)-1
    Local $aPathSplit = _PathSplit($games[$s], $sDrive, $sDir, $sFileName, $sExtension)
    $obj = _IECreate("https://www.google.ch/search?as_st=y&tbm=isch&hl=it&as_q=game+"& $cabinet &"+"& $aPathSplit[3] &"+cover&as_epq=game+"& $cabinet &"+"& $aPathSplit[3] &"+cover&as_oq=&as_eq=&cr=&as_sitesearch=&safe=images&tbs=iar:t,ift:jpg#as_st=y&hl=it&tbs=iar:t,ift:jpg&tbm=isch&q=game+"& $cabinet &"+"& $aPathSplit[3] &"+cover",0,0)
    ConsoleWrite("https://www.google.ch/search?as_st=y&tbm=isch&hl=it&as_q=game+"& $cabinet &"+"& $aPathSplit[3] &"+cover&as_epq=game+"& $cabinet &"+"& $aPathSplit[3] &"+cover&as_oq=&as_eq=&cr=&as_sitesearch=&safe=images&tbs=iar:t,ift:jpg#as_st=y&hl=it&tbs=iar:t,ift:jpg&tbm=isch&q=game+"& $cabinet &"+"& $aPathSplit[3] &"+cover"&@CRLF)
    $sSource = _IEDocReadHTML($obj)
    $aImgURL = _StringBetween($sSource, '"ou":"', '"')
    _IEQuit($obj)

    For $x = 1 to UBound($aImgURL) - 1
        If $x < 2 Then
            InetGet($aImgURL[$x], @ScriptDir & "\img\" & $aPathSplit[3]&".jpg") ;$aRegEx[0])
            ConsoleWrite("-----"&$aPathSplit[3]&@CRLF)
                If @error Then
                    ConsoleWrite("Err" & $aImgURL[$x]&@CRLF)
                EndIf
        Else
            ExitLoop
        EndIf
    Next
Next

 

Edited by rootx
Posted (edited)

IE opens multiple processes:

While True
    $hndIE = WinGetHandle( "[Class:IEFrame]" )
    If Not ishwnd($hndIE) Then
       MsgBox("","","no")
       ExitLoop
    Else
        MsgBox("","","si")
        Local $iPID = WinGetProcess($hndIE)
        ProcessClose($iPID)
    EndIf
WEnd

But you should probably be closing the processes, not the window...same technique.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted (edited)

Mmmmm, bad news google search engine have query limits!!! 4that reason after 30...35 img the script fail! well 4 few images is a usefull script, or we must pay one key to have a lot of query, same logic with gmaps, but here we can try openap database. Thx

PS: When Google search stop the procedure, the script write a log Redownload.txt with the new index without the complete cover, you can use it to restart the script with a new ip....Proxy, Reload router etc... or wait the next day.

#include <String.au3>
#include <ie.au3>
#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=

;Close othe IE process
While True
    $hndIE = WinGetHandle( "[Class:IEFrame]" )
    If Not ishwnd($hndIE) Then
       ExitLoop
    Else
        Local $iPID = WinGetProcess($hndIE)
        ProcessClose($iPID)
    EndIf
WEnd

DirCreate(@ScriptDir&"\img")

$cabinet = "pc"
$type = "jpg"
$width = "800"
$height = "600"

$games = FileReadToArray("C:\Users\rootx\Desktop\lista game pc.txt")

Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = ""
Local $rDownload = @ScriptDir&"\Redownload.txt"

For $s = 1 to UBound($games)-1
    $hndIE = WinGetHandle( "[Class:IEFrame]" )
    If ishwnd($hndIE) Then
        Local $iPID = WinGetProcess($hndIE)
        ProcessClose($iPID)
    EndIf
    Local $aPathSplit = _PathSplit($games[$s], $sDrive, $sDir, $sFileName, $sExtension)
    Local $obj = _IECreate("https://www.google.ch/search?as_st=y&tbm=isch&hl=it&as_q=game+"& $cabinet &"+"& $aPathSplit[3] &"+cover&as_epq=game+"& $cabinet &"+"& $aPathSplit[3] &"+cover&as_oq=&as_eq=&cr=&as_sitesearch=&safe=images&tbs=iar:t,ift:jpg#as_st=y&hl=it&tbs=iar:t,ift:jpg&tbm=isch&q=game+"& $cabinet &"+"& $aPathSplit[3] &"+cover",0,0)
    ConsoleWrite("https://www.google.ch/search?as_st=y&tbm=isch&hl=it&as_q=game+"& $cabinet &"+"& $aPathSplit[3] &"+cover&as_epq=game+"& $cabinet &"+"& $aPathSplit[3] &"+cover&as_oq=&as_eq=&cr=&as_sitesearch=&safe=images&tbs=iar:t,ift:jpg#as_st=y&hl=it&tbs=iar:t,ift:jpg&tbm=isch&q=game+"& $cabinet &"+"& $aPathSplit[3] &"+cover"&@CRLF)
    _IELoadWait($obj)
    $sSource = _IEDocReadHTML($obj)
    $aImgURL = _StringBetween($sSource, '"ou":"', '"')
    If Not IsArray($aImgURL) = 1 Then
        ConsoleWrite("Query limits try to download later "&$games[$s]&@CRLF)
        FileWriteLine($rDownload,$games[$s]&@CRLF)
    Else
        For $x = 1 to UBound($aImgURL) - 1
            If $x < 2 Then
                InetGet($aImgURL[$x], @ScriptDir & "\img\" & $aPathSplit[3]&".jpg",0) ;$aRegEx[0])
                ConsoleWrite("-----"&$aPathSplit[3]&@CRLF)
                ConsoleWrite("xxxxxx" & $aImgURL[$x]&@CRLF)
                    If @error Then
                        ConsoleWrite("Err" & $aImgURL[$x]&@CRLF)
                    EndIf
            Else
                ExitLoop
            EndIf
        Next
    EndIf
    _IEQuit($obj)
Next

 

Edited by rootx

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
×
×
  • Create New...