Sign in to follow this  
Followers 0
John117

Can anyone tell me whats wrong with this script?

3 posts in this topic

Original script is from here:

'?do=embed' frameborder='0' data-embedContent>>

It does not seem to work.

 

Requires ini file. -contents to demo are: -also included ini file

[default]
keywords=shoes, tennis shoes
url=adidas.com
lng=en

I believe it may have to do with the "$a_URLS = StringRegExp($a_URLS, '<(?i)a class=l href="(.*?)">', 3)" section.

Can anyone point me in the right direction on this one please?

#include <inet.au3>
#include <Array.au3>
If Not FileExists(@ScriptDir & "\results") Then DirCreate(@ScriptDir & "\results")
Dim $Pages
Dim $msg
Dim $MatchPagesForWord
$keywords = IniRead("settings.ini", "default", "keywords", "XX")
$keywords = StringSplit($keywords, ",")
;_ArrayDisplay($keywords,0)
$url = IniRead("settings.ini", "default", "url", "XX")
Dim $result[100]
$lng = IniRead("settings.ini", "default", "lng", "XX")
Dim $line[1]

$i = 1
Do
    $result = _Google($keywords[$i], 100, $lng)
    ;_ArrayDisplay($result,0)
    TrayTip("Working on:", $keywords[$i], 1)
    ;_ArrayDisplay($result,0)
    $o = 1
    _ArrayAdd($line, $keywords[$o] & ": ")
    Do
        $match = StringInStr($result[$o], $url)
        If $match <> 0 Then
            If $result[0] <> $o And $o <> 1 Then
                $sep = ", "
            Else
                $sep = ""
            EndIf
            $line[$i] = $line[$i] & $o & ", "
        EndIf
        $o = $o + 1
    Until $o > $result[0]
    $o = 0
    $line[$i] = StringTrimRight($line[$i], 2) & "."
    $fopen = FileOpen(@ScriptDir & "\" & "results\" & $url & "-" & $keywords[$i] & ".txt", 1)
    FileWriteLine($fopen, @YEAR & "." & @MON & "." & @MDAY & " " & @HOUR & ":" & @MIN & " " & $line[$i])
    FileClose($fopen)
    $msg = $msg & $line[$i] & @CRLF
    $i = $i + 1
Until $keywords[0] = $i - 1

TrayTip("Complete!", "...", 1000)
MsgBox(0, 0, $msg)

Func _Google($s_q, $i_resultnum = 10, $lng = "en")
    If Not IsInt($i_resultnum) Then
        SetError(3)
        Return 0
    EndIf
    Local $a_URLS, $s_Source[200]
    $s_Source = _INetGetSource('http://www.google.com/search?hl=' & $lng & '&q=' & StringReplace(StringReplace($s_q, "+", "%2B"), " ", "+") & '&num=' & $i_resultnum)
    ;ConsoleWrite($s_Source & @CRLF)
    If @error Then
        SetError(1)
        Return 0
    EndIf
    $a_URLS = StringRegExp($a_URLS, '<(?i)a class=l href="(.*?)">', 3)
    ;ConsoleWrite($a_URLS & @CRLF)
    If @error Then
        SetError(2)
        Return 0
    EndIf
    Local $a_URLSReturn[UBound($a_URLS) + 1]
    $a_URLSReturn[0] = UBound($a_URLS)
    Local $i_counter
    For $i_counter = 1 To UBound($a_URLS)
        $a_URLSReturn[$i_counter] = $a_URLS[$i_counter - 1]
    Next
    Return $a_URLSReturn
EndFunc   ;==>_Google

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Please EXACTLY describe your problem. "Doesn't seem to work" won't attract many readers wishing to help you.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

This debugged script now generates TrayTips and a MsgBox, and also creates two files, off the script's directory:-
"resultsadidas.com- tennis shoes.txt", and
"resultsadidas.com-shoes.txt".

#include <inet.au3>
#include <Array.au3>
If Not FileExists(@ScriptDir & "\results") Then DirCreate(@ScriptDir & "\results")
Dim $Pages
Dim $msg
Dim $MatchPagesForWord
$keywords = IniRead("settings.ini", "default", "keywords", "XX")
$keywords = StringSplit($keywords, ",")
;_ArrayDisplay($keywords,0)
$url = IniRead("settings.ini", "default", "url", "XX")
Dim $result[100]
$lng = IniRead("settings.ini", "default", "lng", "XX")
Dim $line[1]

$i = 1
Do
    $result = _Google($keywords[$i], 100, $lng)
    ;_ArrayDisplay($result,0)
    TrayTip("Working on:", $keywords[$i], 1)
    ;_ArrayDisplay($result,0)
    $o = 1
    _ArrayAdd($line, $keywords[$o] & ": ")
    Do
        $match = StringInStr($result[$o], $url)
        If $match <> 0 Then
            If $result[0] <> $o And $o <> 1 Then
                $sep = ", "
            Else
                $sep = ""
            EndIf
            $line[$i] = $line[$i] & $o & ", "
        EndIf
        $o = $o + 1
    Until $o > $result[0]
    $o = 0
    $line[$i] = StringTrimRight($line[$i], 2) & "."
    $fopen = FileOpen(@ScriptDir & "\" & "results\" & $url & "-" & $keywords[$i] & ".txt", 1)
    FileWriteLine($fopen, @YEAR & "." & @MON & "." & @MDAY & " " & @HOUR & ":" & @MIN & " " & $line[$i])
    FileClose($fopen)
    $msg = $msg & $line[$i] & @CRLF
    $i = $i + 1
Until $keywords[0] = $i - 1

TrayTip("Complete!", "...", 1000)
MsgBox(0, 0, $msg)

Func _Google($s_q, $i_resultnum = 10, $lng = "en")
    If Not IsInt($i_resultnum) Then
        SetError(3)
        Return 0
    EndIf
    Local $a_URLS, $s_Source[200]
    $s_Source = _INetGetSource('http://www.google.com/search?hl=' & $lng & '&q=' & StringReplace(StringReplace($s_q, "+", "%2B"), " ", "+") & '&num=' & $i_resultnum)
    ConsoleWrite('http://www.google.com/search?hl=' & $lng & '&q=' & StringReplace(StringReplace($s_q, "+", "%2B"), " ", "+") & '&num=' & $i_resultnum & @CRLF)
    If @error Then
        SetError(1)
        Return 0
    EndIf
    $a_URLS = StringRegExp($s_Source, '(?i)href="(.*?)"', 3)
    ;_ArrayDisplay($a_URLS)
    If @error Then
        SetError(2)
        Return 0
    EndIf
    Local $a_URLSReturn[UBound($a_URLS) + 1]
    $a_URLSReturn[0] = UBound($a_URLS)
    Local $i_counter
    For $i_counter = 1 To UBound($a_URLS)
        $a_URLSReturn[$i_counter] = $a_URLS[$i_counter - 1]
    Next
    Return $a_URLSReturn
EndFunc   ;==>_Google

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
Sign in to follow this  
Followers 0