Python: သင်၏ Niche Search သော့ချက်စာလုံးများအတွက်ဂူဂဲလ် Autosuggest Extracts ကို Script
လူတိုင်းက Google Trends ကိုကြိုက်တယ်၊ ဒါပေမယ့် Long Tail Keywords နဲ့ပတ်သက်ပြီးတော့နည်းနည်းလေးခက်တယ်။ ငါတို့ရှိသမျှသည်တရားဝင်ကြိုက်တယ် Google ခေတ်ရေစီးကြောင်းဝန်ဆောင်မှု ရှာဖွေရေးအပြုအမူအပေါ်ထိုးထွင်းသိမြင်မှုရတဲ့အဘို့။ သို့သော်၊ အရာနှစ်ခုကလူများစွာကို၎င်းကိုခိုင်မာသောအလုပ်အတွက်အသုံးပြုခြင်းမှတားဆီးသည်
- သင်ရှာရန်လိုအပ်သည့်အခါ အသစ်သောနယ်ပယ်သော့ချက်စာလုံးများ, အဲဒီမှာ Google Trends တွင်အချက်အလက်အလုံအလောက်မရှိပါ
- google ခေတ်ရေစီးကြောင်းသို့တောင်းဆိုမှုများပြုလုပ်ရန်အတွက်တရားဝင် API မရှိခြင်း - ကျွန်ုပ်တို့ကြိုက်နှစ်သက်သော modules များကိုအသုံးပြုသောအခါ pytrendsသို့ဖြစ်လျှင်ကျွန်ုပ်တို့သည် proxy server များကိုအသုံးပြုရမည်၊ သို့မဟုတ်ပိတ်ဆို့ခံရမည်။
ဤဆောင်းပါး၌ကျွန်ုပ်တိုရေးသားထားသော Python Script ကိုသုံးမည်။ Google Autosuggest မှတဆင့်ခေတ်မှီသောသော့ချက်စာလုံးများကိုတင်ပို့ရန်။
Autosuggest ရလဒ်များကိုအချိန်ကြာလာသည်နှင့်အမျှသိမ်းထားပါ
Google Autosuggest သို့ပို့ရန် Seed သော့ချက်စာလုံး ၁၀၀၀ ရှိသည်။ အပြန်အလှန်အားဖြင့်ကျွန်ုပ်တို့သည် ၂၀၀,၀၀၀ ၀ န်းကျင်ရှိမည် အမြီးရှည် သော့ချက်စာလုံးများ။ ထို့နောက်ကျွန်ုပ်တို့သည်တစ်ပါတ်အကြာတွင်ထပ်တူပြုမှုကိုပြုလုပ်ပြီးမေးခွန်းနှစ်ခုကိုဖြေဆိုရန်ဤအချက်အလက်ဒေတာအစုကိုနှိုင်းယှဉ်ရန်လိုအပ်သည်။
- ဘယ်မေးခွန်းတွေဟာ သော့ချက်စာလုံးအသစ် နောက်ဆုံးသောကာလနှင့်နှိုင်းယှဉ်ပါက? ဤအရာသည်ကျွန်ုပ်တို့လိုအပ်သောအမှုဖြစ်ကောင်းဖြစ်နိုင်သည်။ ဂူဂဲလ်ကထိုမေးခွန်းများသည် ပို၍ အရေးကြီးလာသည်ဟုယူဆသည် - ထိုသို့ပြုလုပ်ခြင်းဖြင့်ကျွန်ုပ်တို့သည်ကိုယ်ပိုင်ဂူဂဲလ် Autosuggest ဖြေရှင်းချက်ကိုဖန်တီးနိုင်သည်။
- ဘယ်မေးခွန်းတွေဟာ သော့ချက်စာလုံးများမရှိတော့ပါ ခေတ်ရေစီးကြောင်း?
ဇာတ်ညွှန်းကအတော်လေးလွယ်ကူတယ်၊ ငါဝေမျှခဲ့တဲ့ code အများစုကို ဒီမှာ။ အဆင့်မြှင့်ထားသောကုဒ်သည်အတိတ်ပြေးများမှအချက်အလက်များကိုသိမ်းဆည်းပြီးအကြံပြုချက်များကိုအချိန်နှင့်အမျှနှိုင်းယှဉ်သည်။ ကျွန်ုပ်တို့သည်ရိုးရိုးရှင်းရှင်းဖြစ်စေရန် file-based databases ကိုရှောင်ရှားခဲ့သဖြင့်အချက်အလက်သိုလှောင်မှုအားလုံးသည်အောက်တွင်ဖော်ပြထားသော CSV ဖိုင်များကိုအသုံးပြုနေသည်။ ဤသည်ကသင့်အား Excel တွင်ဖိုင်တင်သွင်းပြီးသင်၏စီးပွားရေးအတွက်နယ်ပယ်သော့ချက်ကျသောလမ်းကြောင်းများကိုစူးစမ်းလေ့လာစေသည်။
ဒီ Python Script ကိုအသုံးပြုရန်
- သင်၏ autocomplete သို့ keywords.csv သို့ပို့သင့်သောသင်၏ seed keyword ကိုထည့်ပါ
- သင့်လိုအပ်ချက်အတွက် Script settings ကိုချိန်ညှိပါ။
- LANGUAGE: default“ en”
- နိုင်ငံ - default“ us”
- တစ်ပတ်တစ်ကြိမ် run ရန် script ကိုအချိန်ဇယားဆွဲပါ။ ကိုယ်တိုင်ကြိုက်သလိုလည်းကိုယ်တိုင်ဖွင့်နိုင်သည်။
- နောက်ထပ်ခွဲခြမ်းစိတ်ဖြာမှုအတွက် keyword_suggestions.csv ကိုအသုံးပြုပါ။
- ပထမဤအချက်သည် autosuggest တွင်ပထမဆုံးအကြိမ်ပေါ်ပေါက်လာသည့်နေ့ရက်ဖြစ်သည်
- နောက်ဆုံး_မြင်သည်။ဖြေ - နောက်ဆုံးအကြိမ်မေးမြန်းမှုကိုတွေ့ခဲ့ရသည့်ရက်စွဲ
- အသစ် _ ဖြစ်သည်: first_seen == last_seen ဖြစ်ပါကကျွန်ုပ်တို့သည်ဤအရာကိုသတ်မှတ်သည် စစ်မှန်သော - Google autosuggest တွင်ခေတ်ရေစီးကြောင်းရှာဖွေမှုအသစ်များရရှိရန်ဤတန်ဖိုးကိုသာစစ်ထုတ်ပါ။
ဒီမှာ Python Code ပါ
# Pemavor.com Autocomplete Trends
# Author: Stefan Neefischer (stefan.neefischer@gmail.com)
import concurrent.futures
from datetime import date
from datetime import datetime
import pandas as pd
import itertools
import requests
import string
import json
import time
charList = " " + string.ascii_lowercase + string.digits
def makeGoogleRequest(query):
# If you make requests too quickly, you may be blocked by google
time.sleep(WAIT_TIME)
URL="http://suggestqueries.google.com/complete/search"
PARAMS = {"client":"opera",
"hl":LANGUAGE,
"q":query,
"gl":COUNTRY}
response = requests.get(URL, params=PARAMS)
if response.status_code == 200:
try:
suggestedSearches = json.loads(response.content.decode('utf-8'))[1]
except:
suggestedSearches = json.loads(response.content.decode('latin-1'))[1]
return suggestedSearches
else:
return "ERR"
def getGoogleSuggests(keyword):
# err_count1 = 0
queryList = [keyword + " " + char for char in charList]
suggestions = []
for query in queryList:
suggestion = makeGoogleRequest(query)
if suggestion != 'ERR':
suggestions.append(suggestion)
# Remove empty suggestions
suggestions = set(itertools.chain(*suggestions))
if "" in suggestions:
suggestions.remove("")
return suggestions
def autocomplete(csv_fileName):
dateTimeObj = datetime.now().date()
#read your csv file that contain keywords that you want to send to google autocomplete
df = pd.read_csv(csv_fileName)
keywords = df.iloc[:,0].tolist()
resultList = []
with concurrent.futures.ThreadPoolExecutor(max_workers=MAX_WORKERS) as executor:
futuresGoogle = {executor.submit(getGoogleSuggests, keyword): keyword for keyword in keywords}
for future in concurrent.futures.as_completed(futuresGoogle):
key = futuresGoogle[future]
for suggestion in future.result():
resultList.append([key, suggestion])
# Convert the results to a dataframe
suggestion_new = pd.DataFrame(resultList, columns=['Keyword','Suggestion'])
del resultList
#if we have old results read them
try:
suggestion_df=pd.read_csv("keyword_suggestions.csv")
except:
suggestion_df=pd.DataFrame(columns=['first_seen','last_seen','Keyword','Suggestion'])
suggestionCommon_list=[]
suggestionNew_list=[]
for keyword in suggestion_new["Keyword"].unique():
new_df=suggestion_new[suggestion_new["Keyword"]==keyword]
old_df=suggestion_df[suggestion_df["Keyword"]==keyword]
newSuggestion=set(new_df["Suggestion"].to_list())
oldSuggestion=set(old_df["Suggestion"].to_list())
commonSuggestion=list(newSuggestion & oldSuggestion)
new_Suggestion=list(newSuggestion - oldSuggestion)
for suggest in commonSuggestion:
suggestionCommon_list.append([dateTimeObj,keyword,suggest])
for suggest in new_Suggestion:
suggestionNew_list.append([dateTimeObj,dateTimeObj,keyword,suggest])
#new keywords
newSuggestion_df = pd.DataFrame(suggestionNew_list, columns=['first_seen','last_seen','Keyword','Suggestion'])
#shared keywords with date update
commonSuggestion_df = pd.DataFrame(suggestionCommon_list, columns=['last_seen','Keyword','Suggestion'])
merge=pd.merge(suggestion_df, commonSuggestion_df, left_on=["Suggestion"], right_on=["Suggestion"], how='left')
merge = merge.rename(columns={'last_seen_y': 'last_seen',"Keyword_x":"Keyword"})
merge["last_seen"].fillna(merge["last_seen_x"], inplace=True)
del merge["last_seen_x"]
del merge["Keyword_y"]
#merge old results with new results
frames = [merge, newSuggestion_df]
keywords_df = pd.concat(frames, ignore_index=True, sort=False)
# Save dataframe as a CSV file
keywords_df['first_seen'] = pd.to_datetime(keywords_df['first_seen'])
keywords_df = keywords_df.sort_values(by=['first_seen','Keyword'], ascending=[False,False])
keywords_df['first_seen']= pd.to_datetime(keywords_df['first_seen'])
keywords_df['last_seen']= pd.to_datetime(keywords_df['last_seen'])
keywords_df['is_new'] = (keywords_df['first_seen']== keywords_df['last_seen'])
keywords_df=keywords_df[['first_seen','last_seen','Keyword','Suggestion','is_new']]
keywords_df.to_csv('keyword_suggestions.csv', index=False)
# If you use more than 50 seed keywords you should slow down your requests - otherwise google is blocking the script
# If you have thousands of seed keywords use e.g. WAIT_TIME = 1 and MAX_WORKERS = 5
WAIT_TIME = 0.2
MAX_WORKERS = 20
# set the autocomplete language
LANGUAGE = "en"
# set the autocomplete country code - DE, US, TR, GR, etc..
COUNTRY="US"
# Keyword_seed csv file name. One column csv file.
#csv_fileName="keyword_seeds.csv"
CSV_FILE_NAME="keywords.csv"
autocomplete(CSV_FILE_NAME)
#The result will save in keyword_suggestions.csv csv file