Nab hab sej: Tsab Ntawv Google Google Autosuggest Extract ntawm Txoj Kev Tsim Rau Koj Lub Nras Tshawb Nrhiav Lo Lus Qhia

Nab hab sej kom tau ntes Autosuggest ncauj ke

Txhua leej txhua tus nyiam Google Trends, tab sis nws ua yuam kev thaum nws los txog Long Tail Keywords. Peb txhua tus nyiam kev ua haujlwm google tiam sis muab kev pab kom tau txais kev pom txog ntawm kev tshawb nrhiav tus cwj pwm. Txawm li cas los xij, ob yam thaiv tau ntau yam los ntawm kev siv nws rau kev ua haujlwm ruaj khov;

  1. Thaum koj yuav tsum nrhiav tshiab ntsiab lus zoo, ntawd yog cov ntaub ntawv tsis txaus ntawm Google Trends 
  2. Tsis muaj cov ntaub ntawv API tshwj xeeb rau kev thov rau google tiam sis: Thaum peb siv cov qauv zoo li pytrends, tom qab ntawd peb yuav tsum siv proxy servers, lossis peb tau txais kev txwv. 

Hauv tsab xov xwm no, Kuv yuav qhia ib qho Yeeb Yam sej peb tau sau ntawv kom xa cov ntsiab lus tseem ceeb ntawm Google Autosuggest.

Nqa khoom thiab Khaws Autosuggest Cov Sijhawm Sijhawm 

Piv txwv peb muaj 1,000 Lub ntsiab lus noob kom raug xa mus rau Google Autosuggest. Nyob hauv kev xa rov qab, peb yuav zaum tau li ntawm 200,000 ntev cov ntsiab lus tseem ceeb. Tom qab ntawd, peb yuav tsum tau ua qhov qub ib lim tiam tom qab thiab muab cov ntawv sib piv no los teb ob nqe lus nug:

  • Qhov twg nug yog cov ntsiab lus tshiab piv rau lub sijhawm kawg? Nov yog lub rooj sib hais uas peb xav tau. Google xav tias cov lus nug no tau dhau los ua qhov tseem ceeb - los ntawm kev ua li ntawd, peb tuaj yeem tsim peb tus kheej Google Autosuggest kev daws teeb meem! 
  • Qhov twg nug yog keywords tsis ntev cia siab rau?

Cov ntawv yog yooj yim heev, thiab feem ntau ntawm cov code kuv qhia noCov. Tus lej hloov kho tshiab khaws cov ntaub ntawv los ntawm cov khiav dhau los thiab muab piv rau cov lus qhia hauv lub sijhawm. Peb zam cov ntaub ntawv-based databases zoo li SQLite kom nws yooj yim - yog li tag nrho cov ntaub ntawv khaws cia yog siv CSV cov ntaub ntawv hauv qab no. Qhov no tso cai rau koj los import cov ntawv hauv Excel thiab tshawb nrhiav cov ntsiab lus tseem ceeb rau koj txoj kev lag luam.

Los Siv Cov Ntawv No Python

  1. Ntaus koj cov noob lo lus tseem ceeb uas yuav tsum xa mus rau lub autocomplete: keywords.csv
  2. Kho cov ntawv chaw rau koj xav tau:
    • LUS ASKIV: vim li cas “en”
    • TEB CHAWS: vim li cas “peb”
  3. Teem cov tsab ntawv khiav ib zaug ib lub lim tiam. Koj kuj tuaj yeem khiav nws manually raws li koj xav tau.
  4. Siv keyword_suggestions.csv rau kev txheeb xyuas ntxiv:
    • thawj_seen: Qhov no yog hnub uas cov lus nug tau tshwm sim rau thawj zaug hauv lub autosuggest
    • kawg_seen: hnub uas cov lus nug tau pom lub sijhawm kawg
    • yog_ntxawm: yog first_seen == last_seen peb teeb no rau muaj tseeb - Tsuas yog lim rau ntawm tus nqi no kom tau txais cov kev tshawb nrhiav tshiab hauv Google autosuggest.

Ntawm no yog Tus Nab Npawb

# 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

Rub lub Py Py Lus

Yuav ua li cas koj xav hais tias?

Qhov Web site no siv Akismet los txo cov kev pabcuam. Kawm li cas koj cov ntaub ntawv tawm tswv yim tiav.