Jump to content

Recommended Posts

Posted

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
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

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

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
  • Recently Browsing   0 members

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