Python批量获取爱站关键词带搜索量
通过Python批量获取爱站关键词带搜索量也是相对比较简单,因为都在网页源代码当中,都可以用万能的正则表达式来匹配出来,不知道的不够深入的都自行脑补,下面的截图也没截全正则表达式部分,几乎网页源代码中的采集思路都可以大概是这样操作,先请求url,url变得部分用for遍历本地文件实现批量操作,大神就忽略吧!另外只要词根够多的话是可以采集很多的,还有就是翻页,爱站要会员才能出数据,这里不写了,自己模拟登录一下就可以翻页采集更多关键词,下面还是直接上代码:
在sublime运行print出来的结果如下:
导出csv的结果如下:
Python批量获取爱站关键词带搜索量源码:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import reimport urllibop_csv_write=open('ciku.csv','a')op_csv_write.write('关键词,搜索量\n')for keyword in open('word.txt'): word=keyword.strip() url='http://ci.aizhan.com/%s/'%word # print url html=urllib.urlopen(url).read() # print html if '没有相关的关键词' in html: pass else: r=re.compile(r'<td class="blue t_l"><a href="http://www\.baidu\.com/baidu.*?" target="_blank" rel="nofollow">(.*?)</a></td>[\s\S]*?<td align="right">(\d+)</td>') a=re.findall(r,html) for i in a: # print i f=','.join(i) w=re.compile('<font color="#FF0000">|</font>') b = w.sub('',f) print b op_csv_write.write(b+'\n') |
文章仅供交流学习之用,欢迎转载,转载请保留原文链接,让博主有写的欲望!thanks!

浙公网安备 33010602011771号