最近如果还有做站的话,感觉走词库越来越重要了,准确的说,是其他路不好走了。除了花钱直接从爱站、站长工具、5118下载词库之外,我们还可以通过百度凤巢的关键词规划师工具收集关键词建立自己的词库。
获取接口
注册账号
目前是否可以免费注册我也不确定,可以参考之前的文章《如何利用百度推广批量挖掘长尾关键词》我也没怎么关注,大家自己试
拥有账号,登录百度凤巢(https://fengchao.baidu.com/)——搜索推广——进入关键词规划师界面
抓包
浏览器F12进入开发者模式,点击Netword,然后在关键词规划师中输入关键词进行查询,抓包获取如下图:
header中获取请求的URL网址、POST的数据、headers信息。然后就是python代码的实现。
python实现简易代码
import requests
import json
url = 'https://fengchao.baidu.com/hairuo/request.ajax?path=lightning%2FGET%2FKeywordSuggestService%2FgetKeywordRecommendPassive&reqid=4b534c48-b80e-xxxxx'
headers = {
'accept': 'application/json',
'content-type': 'application/x-www-form-urlencoded',
'cookie': 'xxxxx',
'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Safari/537.36 SE 2.X MetaSr 1.0'
}
params = {
"keyWordRecommendFilter":{"device":0,
"positiveWords":[],
"negativeWords":[],
"fieldFilters":[],
"keywordRecommendReasons":[],
"searchRegions":"9999999",
"regionExtend":False,
"removeDuplicate":False,
"removeBrandWords":False,
"removeCampaignDuplicate":False
},
"source":"web","queryBy":0,"pageNo":1,"pageSize":3000,"wordQuerys":["seo"],"querySessions":["seo"],"entryMessage":"kr_station"
}
data = {
'reqid': '4b534c48-b80e-xxxxx',
'userid': 'xxxxx',
'token': 'xxxxx',
'path': 'lightning/GET/KeywordSuggestService/getKeywordRecommendPassive',
'params': json.dumps(params)
}
res = requests.post(url=url, data=data, headers=headers)
res = res.json()['data']['keywordRecommendItems']
for r in res:
print(r['keyword'])
以上可以打印出seo挖掘的3000个关键词。关键词在params数据中,header和data中的数据需要修改成自己的。获取数据示例如下:
{
"data": {
"logId": "13961856165454326160",
"wordsCount": 723,
"keywordRecommendItems": [
{
"keyword": "seo什么意思啊",
"averagePv": 1,
"averagePvPc": 0,
"averagePvMobile": 0,
"averageDayPv": 1,
"averageDayPvPc": 0,
"averageDayPvMobile": 0,
"competition": 3,
"recommendPrice": 1.24,
"recommendPricePc": 1.58,
"recommendPriceMobile": 1.24,
"showReasons": [],
"matchType": 2,
"phraseType": 3,
"campaignId": 0,
"adgroupId": 0,
"groupName": "疑问词",
"averageMonthPv": 36,
"averageMonthPvPc": 9,
"averageMonthPvMobile": 27,
"show": 39,
"click": 8,
"competitionPc": 3,
"competitionWise": 3,
"wordId": 481396789
},
{
"keyword": "seo是什么意思 为什么要做seo",
"averagePv": 0,
"averagePvPc": 0,
"averagePvMobile": 0,
"averageDayPv": 0,
"averageDayPvPc": 0,
"averageDayPvMobile": 0,
"competition": 3,
"recommendPrice": 1.24,
"recommendPricePc": 1.58,
"recommendPriceMobile": 1.24,
"showReasons": [],
"matchType": 2,
"phraseType": 3,
"campaignId": 0,
"adgroupId": 0,
"groupName": "疑问词",
"averageMonthPv": 7,
"averageMonthPvPc": 1,
"averageMonthPvMobile": 6,
"show": 39,
"click": 8,
"competitionPc": 3,
"competitionWise": 3,
"wordId": 6868879822
},
],
"keywordRecommendReasons": [],
"totalCount": 723
},
"expand": {},
"status": 0,
"errors": []
}
数据中参数非常多,可以自行根据需求对关键词进行过滤、将关键词修改为变量,也可以实现批量抓取
转载请注明:思享SEO博客 » python实现百度凤巢关键词规划师提取关键词