uh hello guys welcome to this video so
in this video i will show you a python
script which will
actually build out a keyword explorer
where you can actually get keyword ideas
related to google search and for this
purpose we will be using the google
autocomplete and suggestions api google
autocomplete and suggest api i just
written this python script right here
which actually make use of that google
api to get long long-term longtail
keywords so that you can rank your
youtube videos or blogs so this is
actually a python script and uh if i
just run this python script so just see
as i run this python script here you
just need to specify a seed keyword so
as i run this python script the user
will be asked to input a keyword so you
can enter any keyword here and then it
will give you the suggestions and
autocomplete so we simply write here
python script 2 so we are just writing
this seed keyword the basic keyword
right here now it will autocomplete
everything so as i click enter you will
see it will fetch all the suggestions
coming from the autocomplete and suggest
api and it will store all those keywords
longtail keywords inside a csv file so
just wait it actually takes 5 to 10
seconds and then you can see it has
saved 245 longtail keywords inside the
csv file and if i try to open this file
you will see that these are the keywords
right here you can
see so you can see it has made a
complete list where it actually
autocomplete and it has extracted all
these longtail keywords which will help
you in ranking your website or making
youtube videos so it's a very awesome
application what it is actually doing
behind the scenes whenever you go to
google.com as you type the keyword these
autocomplete suggestions which come
right here you will see these are called
autocomplete suggestions so we are
programmatically fetching all these
suggestions by a python script and
saving it inside a csv file for this we
are using this google autocomplete
api and also we are using the google
suggest api as
well so which actually makes use
of to give you suggestions so for this
we don't need to install any keyword
right here so the full script is given
in the description of this video so now
let me show you how to build this script
from scratch so just make a simple app
py file and first of all we need to
import the required modules the request
module we need to import then we need to
also import the csv module and then we
also need to import the time module and
then we specify or we
actually take the user input and we take
the input of the user here we actually
allow the user to enter a keyword base
keyword as the user write the keyword
but we will actually call this function
which is generate long tail
keyword so we define this function and
inside this function we are actually
calling
this user input so we are passing this
to this function so now we just need to
define this function so this will be
generate
longtail
keywords and here we specify our user
input which is passed as an argument so
now in this
function you just need to actually make
a
uh variable here right here which will
be long tail keywords which will be an
empty array so we declare this set array
and then we extract all the seed phrases
or the autocomplete suggestions using
the base
keyword like
this and then we simply concatenate this
by space and then
chr and
then we loop through for i in range and
we basically loop through this is
actually as sky code here of each
character 97 to 123 so this is
essentially going from a to z
alphabetically and uh after
that we loop through each phrase or for
phrase and seed
phrases and then now to actually inside
this loop we need
to get the suggestions for getting the
suggestions we will define another
function right here get
suggestions using the
phrase so we can print out this seed
phrase so that you can actually see what
is
happening so now we just need to define
this function get suggestions which will
actually extract all the suggestions for
us and inside this function we are
passing the phrase or the keyword you
may
say so inside this we need to hit a url
so this url is autocomplete and suggest
api so this is provided by google it's
completely free you can use it unlimited
number of time so this is actually the
endpoint we are making a simple get
request https suggest
queries.google.com/complete/ search so
here we just need to make a simple get
request and just here we specify the
parameters which is your browser client
it can be chrome or firefox but you just
need to provide here firefox which works
best and then the second parameter which
is your
keyword then we simply make the request
to get the
response so here we specify use the
request module the get
method to the url and alongside with the
parameters uh after that if the response
comes we can simply print out the
response and if the response comes here
we will check inside this if condition
that if the
response status code is equal to 200 in
that case we need
to actually return this
response response dot
json like
and if any sort of exception take place
then we just need to print out the
exception and return this empty
array and if the response is not 200
then also we need to return empty array
so this is actually a very simple
function we specify the keyword then it
actually make this get request to this
api google suggest autocomplete api and
we get all the suggestions and then we
return those suggestions from this
function that's all
so at this moment of time if i want to
execute
this so it is saying that uh invalid
syntax on line number 28
uh just wait i think i made a mistake
right here which is
uh just wait the full script is given
guys in the description so no no need to
worry about
it uh i think on this line sorry let me
just see paste
it
so again if i run
this here you need to specify the base
keyword so python script
2 so it is saying that base keyword is
not defined on line
number
28 oh sorry this is user input sorry
just need to call this space
keyword so as you specify your keyword
you will
see it will generate this response right
here it you can see that all this 200
response coming python script 2 a and
then b c d e f gh so alphabetically we
are getting all these suggestions now we
just need to display these suggestions
and store it in a csv file so after we
get these suggestions right in this
variable
uh now we just need to longtail keywords
we need to update this with these
suggestions and then we just need to
sleep for a certain amount of time
because if you don't write this line if
you don't pause you may be banned for
some time for using so to
avoid being banned so we put some delay
to
and then we return these suggestions in
a sorted way in a list longtail
keywords so that's
all now we get these keywords so after
that we actually save these keywords
into a csv file so save to csv and we
pass this results so now we can define
this function which will actually save
this data into a csv file so save to
csv get the keywords and the file name
you can give any file name let's suppose
i say results dot cv
csv and then we open
this file name in a right mode and new
line encoding is your
utf8 as cs csv file and then
we write a very basic code using the csv
module we save this csv file like
this and then we loop through all the
keywords like this for each keyword we
write this inside your csv file
and then we simply write a line that
uh all keywords
saved uh that's all so this is actually
a python script so if i try to execute
now let me take another keyword here so
i will say javascript program 2 i def i
take a different keyword now so now i
need to generate all the autocomplete
suggestions so you will see it will
suggest all these suggestions so it will
take around about 5 to 10 seconds to
extract all the suggestions and
autocomplete queries on longtail
keywords and once it is completed it
will store all these suggestions in a
csv file you'll see that and this is
really good guys if you are making
videos and blogs uh you don't need to
buy any keyword tool this python script
will fetch all the suggestions for you
from google and then these longtail
keywords will be very much helpful for
you so you can see that the full script
guys is given in the description of this
video if you need the full script you
can see
that and thank you very much for
watching this video please hit that like
button subscribe the channel and also
check out my website freemediattools.com
uh which contains thousands of tools