Python SEO关键字研究工具:Google AutoComplete,人们还会询问和相关搜索
#python #webscraping #seo #demo

Intro

这是一个简单的用户指南,可帮助您开始使用seo-keyword-research-tool

SEO Keyword Research Tool是一个python软件包,旨在生成用于SEO目的的关键字。该软件包是available on PyPi,可以在Python项目中安装和使用,也可以用作CLI。它用于使用Google AutocompleteRelated SearchesPeople also ask生成关键字想法,并将它们保存到TXT,CSV,JSON文件中。

此工具使用SerpApi作为从Google搜索结果中解析数据的工具。其他搜索引擎即将推出。

seo-keyword-research

演示

image

安装

$ pip install seo-keyword-research-tool

ð注意:如果要将此工具用于个人或商业目的,则必须在SerpApi上注册并获取自己的API密钥(免费计划)。使用的默认API密钥用于信息目的,仅在CLI中起作用。

确保您的计算机上有Python installed

使用前,您需要定义your API key from SerpApi。有几种方法:

  • 用密钥添加环境变量API_KEY$ export API_KEY=<API_KEY>(用于基于Linux的终端)
  • 直接在代码中添加您的密钥:SeoKeywordResearch.api_key = "your_api_key"(仅适用于代码使用)

cli用法

您可以通过在终端中输入可用的用法选项:

$ seo -h

可用参数

SerpApi SEO Keyword Research Tool [-h] -q  [-e  [...]] [-dl] [-st] [-ak] [-gd] [-gl] [-hl]

Extract keywrods from: Google Autocomplete, People Also Ask, and People Also Search and saves data to CSV/JSON/TXT.

optional arguments:
  -h, --help            show this help message and exit
  -q , --query          Search query (required).
  -e  [ ...], --engines  [ ...]
                        Choices of engines to extract: Autocomplete (ac), Related Searches (rs), People Also Ask (rq). You can select multiple engines. All engines are selected by default.
  -dl , --depth-limit   Depth limit for People Also Ask. Default is 0, first 2-4 results.
  -st , --save-to       Saves the results in the current directory in the selected format (CSV, JSON, TXT). Default CSV.
  -ak , --api-key       Your SerpApi API key: https://serpapi.com/manage-api-key. Default is a test API key to test CLI.
  -gd , --domain        Google domain: https://serpapi.com/google-domains. Default google.com.
  -gl , --country       Country of the search: https://serpapi.com/google-countries. Default us.
  -hl , --lang          Language of the search: https://serpapi.com/google-languages. Default en.

Found a bug? Open issue: https://github.com/chukhraiartur/seo-keyword-research-tool/issues

ð注意:您可以在任何组合中使用任何可用的参数。您可以在下面看到它们的完整描述。


要获得特定查询的结果,您需要定义--query参数(或简短:-q):

$ seo -q "python how to"

ð注意:这是一个必需的参数。

输出

{
  "auto_complete": [
    "python how to add to a list",
    "python how to round to 2 decimals",
    "python how to install pip",
    "python how to comment out a block",
    "python how to sort a list",
    "python how to call a function",
    "python how to reverse a string",
    "python how to write to a file",
    "python how to add to a dictionary",
    "python how to convert string to int",
    "python how to remove item from list",
    "python how to split a string",
    "python how to open a file",
    "python how to reverse a list",
    "python how to concatenate strings"
  ],
  "related_searches": [
    "python for beginners",
    "python course",
    "python code examples",
    "python for beginners pdf",
    "learn python",
    "python w3schools",
    "python download",
    "python programming"
  ],
  "related_questions": [
    "How do I start programming in Python?",
    "How do I teach myself Python?",
    "Is Python easy to learn?",
    "Can I self teach myself Python?"
  ]
}
Saving data in CSV format...
Data successfully saved to python_how_to.csv file

要从所有受支持的引擎中获得结果,您无需通过引擎参数(如上所述)。如果您想从一个或两个选定的引擎中获得结果,则需要定义--engine参数(或简短:-e)除以一个空间,例如ac rs(自动完成和相关搜索):

$ seo -q "lofi" -e ac
value 引擎
ac 自动完成
rs 相关搜索(人们也搜索)
rq 相关问题(人们也问)

输出

{
  "auto_complete": [
    "lofi girl",
    "lofi music",
    "lofi hip hop",
    "lofi boy",
    "lofi beats",
    "lofi jersey city",
    "lofi study",
    "lofi meaning",
    "lofi girl 34",
    "lofi youtube",
    "lofibra",
    "lofi study music",
    "lofi girl youtube",
    "lofi girl lore",
    "lofi girl synthwave boy"
  ]
}
Saving data in CSV format...
Data successfully saved to lofi.csv file

您可以通过定义--domain(或简短:-gd)参数将默认的Google domain google.com更改为supported domains list的任何一个:

$ seo -q "big ben" -e rs rq -gd "google.co.uk"

输出

{
  "related_searches": [
    "big ben london",
    "big ben country",
    "big ben clock",
    "big ben facts",
    "how old is big ben",
    "why is big ben called big ben",
    "why is big ben famous",
    "big ben tickets"
  ],
  "related_questions": [
    "Is Big Ben still under construction 2023?",
    "Why is Elizabeth Tower called Big Ben?",
    "How much does it cost to go inside Big Ben?",
    "Can you go inside Big Ben?"
  ]
}
Saving data in CSV format...
Data successfully saved to big_ben.csv file

另外,您可以使用--country(或简短:-gl)来更改搜索的默认国家us(美国),并将其设置为supported country codes list

$ seo -q "hotel in" -e rs -gl de

输出

{
  "related_searches": [
    "cheap hotel in germany",
    "cheap hotel in cologne, germany",
    "hotel in baesweiler restaurant",
    "hotel in baesweiler telefonnummer",
    "germany hotel booking website",
    "hotel baesweiler speisekarte",
    "germany hotel address",
    "hotel baesweiler öffnungszeiten"
  ]
}
Saving data in CSV format...
Data successfully saved to hotel_in.csv file

如果要更改搜索的默认语言en(英语),则需要使用--language(或简短:-hl)参数并将其设置为supported language codes list

$ seo -q "anime" -e ac -hl "ja" 

输出

{
  "auto_complete": [
    "アニメ",
    "アニメイト",
    "アニメーション",
    "アニメ無料",
    "アニメ映画",
    "アニメ 英語",
    "アニメダンス",
    "アニメイト 池袋",
    "アニメ 2023",
    "アニメ人気",
    "アニメ9",
    "アニメ無料サイト",
    "anime expo",
    "anime girl",
    "anime store japan"
  ]
}
Saving data in CSV format...
Data successfully saved to anime.csv file

保存搜索结果的默认文件类型是CSV。您可以使用--save-to(或简短:-st)参数将其更改为JSONTXT

$ seo -q "coffee" -st json

输出

{
  "auto_complete": [
    "coffee near me",
    "coffee belvidere il",
    "coffee rockford",
    "coffee crush",
    "coffee nearby",
    "coffee table",
    "coffee crush menu",
    "coffee maker",
    "coffee shop",
    "coffee cake recipe",
    "coffee shops rockford il",
    "coffee grinder",
    "coffee shops rockford",
    "coffee meets bagel",
    "coffee creamer"
  ],
  "related_searches": [
    "coffee near me",
    "coffee types",
    "coffee beans",
    "coffee benefits",
    "coffee starbucks",
    "coffee origin",
    "coffee plant",
    "coffee tree"
  ],
  "related_questions": [
    "Is coffee good for health?",
    "How coffee affects the body?",
    "What are the 4 types of coffee?",
    "What are 10 benefits of coffee?"
  ]
}
Saving data in JSON format...
Data successfully saved to coffee.json file

当您开放人们还会询问结果时,它会加载更多结果。

  • 默认值:

image

  • 结果之一是开放的:

image

因此,如果您打开所有初始结果,那意味着您会看到隔壁的结果。

--depth-limit(或简短:-dl)的人也可以从0设置为4。对于每个深度极限值,返回的结果数呈指数增长。以下是一个表,显示了深度限制参数如何影响:

深度极限 结果数 解释
0 4 标准结果
1 12 4*2 = 8 + 4 = 12
2 36 8*3 = 24 + 12 = 36
3 108 24*3 = 72 + 36 = 108
4 324 72*3 = 216 + 108 = 324

ð注意:这是逻辑对google.com域的工作方式,在其他域上可能有所不同。

深度2的示例意味着我们打开所有标准结果,然后在加载新结果后,我们打开它们并等到加载新的结果:

$ seo -q "minecraft" -e rq -st txt -dl 2

输出

{
  "related_questions": [
    "Is Minecraft OK for a 7 year old?",
    "Is Minecraft appropriate for a 5 year old?",
    "Can I play Minecraft for free?",
    "Is Roblox better than Minecraft?",
    "Is Minecraft good for kids?",
    "Is Minecraft appropriate for 4 year olds?",
    "Is Minecraft OK for 18 year olds?",
    "Is 15 too old to play Minecraft?",
    "Why is my son obsessed with Minecraft?",
    "Is Minecraft OK for 2 year olds?",
    "What is Roblox age limit?",
    "Do 30 year olds play Minecraft?",
    "What is Roblox age limit?",
    "Is Minecraft OK for 2 year olds?",
    "What is Roblox age limit?",
    "Is 15 too old to play Minecraft?",
    "Is Roblox ok for a 40 year old?",
    "Are there inappropriate games on Roblox?",
    "Why is Fortnite not for kids?",
    "Do 30 year olds play Minecraft?",
    "Is Minecraft OK for 2 year olds?",
    "Is Minecraft OK for 18 year olds?",
    "How long is Minecraft free?",
    "How to get Minecraft for free legally?",
    "How long is 100 Minecraft day?",
    "Does Minecraft cost per month?",
    "How long does 1 days in Minecraft last?",
    "What is the free version of Minecraft called?",
    "How to download real Minecraft without money?",
    "How much does Minecraft cost?",
    "Which is bigger Minecraft or Roblox?",
    "Who is the best Minecraft player alive?",
    "How do I get Robux for free?",
    "What parents need to know about Roblox?",
    "What is better fortnite or Roblox?",
    "Who is PvP God in Minecraft?",
    "Who is the clutch god in Minecraft?",
    "Who is the Minecraft King?",
    "Is Minecraft good for ADHD?",
    "What is the appropriate age to play Minecraft?",
    "Why do autistic kids like Minecraft so much?",
    "Why is my son obsessed with Minecraft?",
    "Why is my kid addicted to Minecraft?",
    "Is Minecraft good for the brain?",
    "Is 16 too old to play Minecraft?",
    "Is Minecraft addictive game?",
    "What is Roblox age limit?",
    "What age is appropriate for Roblox?",
    "Is Roblox ok for a 40 year old?",
    "Are there inappropriate games on Roblox?",
    "Why is Fortnite not for kids?",
    "How do I make Roblox safe for my child?",
    "Should I let my child chat on Roblox?",
    "Is Roblox ok for a 40 year old?"
  ]
}
Saving data in TXT format...
Data successfully saved to minecraft.txt file

内编码用法

您也可以在代码中使用此工具。实际上,您在CLI中输入的论点传递给SeoKeywordResearch类。

SeoKeywordResearch类导入您的文件:

from SeoKeywordResearch import SeoKeywordResearch

之后,您需要创建此类的对象并传递所有必要的参数:

keyword_research = SeoKeywordResearch(
    query='starbucks coffee',
    api_key='<your_serpapi_api_key>',
    lang='en',
    country='us',
    domain='google.com'
)

要从特定引擎中提取数据,您需要使用适当的方法。在下面的示例中,我显示了如何创建字典并添加键的所需数据:

data = {
    'auto_complete': keyword_research.get_auto_complete(),
    'related_searches': keyword_research.get_related_searches(),
    'related_questions': keyword_research.get_related_questions(depth_limit=1)
}

ð注意:get_related_questions()方法具有depth_limit参数,该参数允许您加载更多人的结果。

您可以使用以下方法使用方便的格式来保存数据:

keyword_research.save_to_csv(data)
keyword_research.save_to_json(data)
keyword_research.save_to_txt(data)

如果您需要以JSON格式打印数据,请使用以下方法:

keyword_research.print_data(data)

输出

{
  "auto_complete": [
    "starbucks coffee menu",
    "starbucks coffee cups",
    "starbucks coffee traveler",
    "starbucks coffee gear",
    "starbucks coffee drinks",
    "starbucks coffee pods",
    "starbucks coffee sizes",
    "starbucks coffee creamer",
    "starbucks coffee cake",
    "starbucks coffee traveler price",
    "starbucks coffee bags",
    "starbucks coffee beans",
    "starbucks coffee near me",
    "starbucks coffee mugs",
    "starbucks coffee press"
  ],
  "related_searches": [
    "starbucks coffee menu",
    "starbucks coffee price",
    "starbucks near me",
    "starbucks coffee beans",
    "starbucks coffee cups",
    "starbucks coffee bag size",
    "starbucks coffee on sale this week",
    "amazon starbucks coffee instant"
  ],
  "related_questions": [
    "Which one is the best coffee in Starbucks?",
    "Which coffee is Starbucks famous for?",
    "What coffee is sold most at Starbucks?",
    "What is the Starbucks drink for St Patrick's Day?",
    "Which Starbucks coffee is best for beginners?",
    "How do I choose a Starbucks coffee?",
    "Why is Starbucks coffee so popular?",
    "Who is known for the best coffee?",
    "What is the most ordered drink in the world?",
    "What is the most expensive drink at Starbucks?",
    "What is the name of the green coffee at Starbucks?",
    "Does Starbucks have a healthy green drink?"
  ]
}

链接

可以随意打开错误问题,不起作用,要添加的功能或与Google自动完成,相关搜索或人员有关的任何其他功能。

如果您希望将其他功能添加到此演示项目中,或者您想查看其他一些由Serpapi制定的项目,write me a message


加入我们的Twitter | YouTube

添加一个Feature Requestð«或Bugð