ad

Saturday, 7 November 2015

Basic Linear Search Algorithm for web scraping and many other stuff

Basic Automation Algorithm

There's plenty of techniques used in bots automation, they use different tricks and technique but the most common one is called Linear search. It's also quite useful in web scraping.

Imaging you've a page and you intend to search for certain word. Your first step would be to either convert it to array or some organized format so it can be manipulatedThere's plenty of techniques used in bots automation, they use different tricks and technique but the most common one is called Linear search. It's also quite useful in web scraping.

Imaging you've a page and you intend to search for certain word. Your first step would be to either convert it to array or some organized format so it can be manipulated
There's plenty of techniques used in bots automation, they use different tricks and technique but the most common one is called Linear search. It's also quite useful in web scraping.

Imaging you've a page and you intend to search for certain word. Your first step would be to either convert it to array or some organized format so it can be manipulated.
Basic Automation Algorithm

There's plenty of techniques used in bots automation, they use different tricks and technique but the most common one is called Linear search. It's also quite useful in web scraping.

Imaging you've a page and you intend to search for certain word. Your first step would be to either convert it to array or some organized format so it can be manipulated.
Basic Automation Algorithm

There's plenty of techniques used in bots automation, they use different tricks and technique but the most common one is called Linear search. It's also quite useful in web scraping.

Imaging you've a page and you intend to search for certain word. Your first step would be to either convert it to array or some organized format so it can be manipulated
 
 
 
 
Imaging you've a page and you intend to search for certain word. Your first step would be to either convert it to array or some organized format so it can be manipulated. There's plenty of techniques used in bots automation, they use different tricks and technique but the most common one is called Linear search. It's also quite useful in web scraping.

//Basic function declaration.
//Accepts two arguements, $array that we'll search in, and $target_word we wanna search for.
function find_word($array, $target_word) {
   
    // Here we being our basic for loop. We start 1 to 0, until i reaches arrays length, then we increment i
    for(var $i = 0; $i < $array.length; ++$i){
       
        // While looping it checks where $array[$i] <-- $i here represents a number that started from 0. And the whole expression
        // represents first array value. It it loops again, i will have value of 1 $array[1] will respresent 2nd value of array.
        // Then it checks if $array[$i] is equal the word we're looking for, if it finds the word, it will return the index or array position
        // where it was found
        if ($array[$i] == $target_word) {
            return $i;
        }
       
    }
   
    // If loop fails to find the word, it'll return -1, means it couldn't find the word.
    return -1;
}

find_word(["jon", "tom", "brown", 1, 0], "borwn");

No comments:

Post a Comment