Python批量采集百度下拉框关键词

批量采集百度下拉框关键词之前用shell写了一下,现在用python写一下,环境是windows–sublime2的编辑器,大概就是用urllib爆api然后用正则表达式匹配出关键词内容,最后利用for函数来实现批量操作,导出的话看回我之前的一些python小脚本就可以实现,很简单吧,下面的代码粗糙,不过还是请看:
python采集下拉框关键词
用shell写的批量采集百度下拉框关键词脚本链接在这里https://bigwayseo.com/452
Python批量采集百度下拉框关键词源码:

#encoding=utf-8
import urllib
import re

import sys
reload(sys)
sys.setdefaultencoding("utf-8")
for word in open('kws.txt'):
    url='https://suggestion.baidu.com/su?wd=%s'%urllib.quote_plus(word)

    html=urllib.urlopen(url)
    content=html.read().decode('gbk','ignore')
    html.close()
    # print content
    r=re.compile(r'"(.+?)"')
    keywords=re.findall(r,content)
    for kws in keywords:
        print kws

篼雨seo小脚本分享,转载请保留原文链接!

Leave a Comment