Python批量采集百度下拉框推荐词教程

微信扫一扫,分享到朋友圈

Python批量采集百度下拉框推荐词教程

人生苦短,我用Python,从入门到放弃,在到学会装X,这里是一份装X指南,教你如何用Python批量采集百度下拉框推荐词教程。

 

首先,新建文件名,保存为py后缀,将下面代码复制到sublime编辑中:

#encoding=utf-8
import requests,json,urllib

for word in open('kws.txt',encoding='utf-8'):
  url='https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=%s&sugmode=2&json=1&p=3&sid=1427_21091_21673_22581&req=2' % urllib.parse.quote_plus(word)
  html=requests.get(url).text

  html=html.replace('window.baidu.sug(','')

  html=html.replace(');','')
  #print (html)
  html=json.loads(html)
  #print (html['s'])
  for i in html['s']:
    print (i)

 

采集结果如图:

下拉词采集

 

复制以下代码,将采集关键词打印到word文档:

#encoding=utf-8
import requests,json,urllib
opencsv=open('word.csv','a+')
for word in open('kws.txt',encoding='utf-8'):
  url='https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=%s&sugmode=2&json=1&p=3&sid=1427_21091_21673_22581&req=2' % urllib.parse.quote_plus(word)
  html=requests.get(url).text

  html=html.replace('window.baidu.sug(','')

  html=html.replace(');','')
  #print (html)
  html=json.loads(html)
  #print (html['s'])
  for i in html['s']:
    print (i)
    opencsv.write('%s\n'%i)

 

打开word文档,如图:

关键词word文档

 

以上就是用Python批量采集百度下拉推荐词的完整教程。

赞赏

微信赞赏支付宝赞赏

我还没有学会写个人说明!
上一篇

Python批量采集百度相关搜索词教程

下一篇

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

你也可能喜欢

评论已经被关闭。

插入图片

排行榜

    抱歉,30天内未发布文章!

排行榜

    抱歉,30天内未发布文章!
返回顶部