How to resolve the algorithm Yahoo! search interface step by step in the AutoHotkey programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Yahoo! search interface step by step in the AutoHotkey programming language

Table of Contents

Problem Statement

Create a class for searching Yahoo! results. It must implement a Next Page method, and read URL, Title and Content from results.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Yahoo! search interface step by step in the AutoHotkey programming language

Source code in the autohotkey programming language

test:
yahooSearch("test", 1)
yahooSearch("test", 2)
return

yahooSearch(query, page)
{
  global
  start := ((page - 1) * 10) + 1
  filedelete, search.txt
  urldownloadtofile, % "http://search.yahoo.com/search?p=" . query
  . "&b=" . start, search.txt
  fileread, content, search.txt
  reg = <a class="yschttl spt" href=".+?" >(.+?)</a></h3></div><div class="abstr">(.+?)</div><span class=url>(.+?)</span>
  
  index := found := 1
  while (found := regexmatch(content, reg, self, found + 1))
  {
    msgbox % title%A_Index% := fix(self1)
    content%A_Index% := fix(self2)
    url%A_Index% := fix(self3)
  }
}

fix(url)
{
if pos := instr(url, "</a></h3></div>")
StringLeft, url, url, pos - 1
url := regexreplace(url, "<.*?>")
return url
}


  

You may also check:How to resolve the algorithm Make directory path step by step in the NewLISP programming language
You may also check:How to resolve the algorithm Tau function step by step in the Forth programming language
You may also check:How to resolve the algorithm Sieve of Eratosthenes step by step in the Janet programming language
You may also check:How to resolve the algorithm Percolation/Mean run density step by step in the Wren programming language
You may also check:How to resolve the algorithm Farey sequence step by step in the Crystal programming language