当前位置:编程学习 > python >>

python结合shell查询google关键词排名

最近老婆大人的公司给老婆大人安排了一个根据关键词查询google网站排名的差事。老婆大人的公司是做seo的,查询的关键词及网站特别的多,看着老婆大人这么辛苦的重复着查询工作,心疼啊。所以花点时间用python写了一个根据关键词搜索网站排名的py脚本。
在写这个脚本之前,我也曾在网站搜索过关于在google查排名的脚本。很多是利用google的api。但是我测试了一下,不准。所以,自己写一个吧。
脚本内容如下:(关键词我在网站随便找了几个。以做测试使用)
1. #vim keyword.py
2. import urllib,urllib2,cookielib,re,sys,os,time,random
3. cj = cookielib.CookieJar()
4. vibramkey=['cheap+five+fingers','vibram+five+fingers']
5. beatskey=['beats+by+dre','beats+by+dre+cheap']
6. vibramweb=['vibramforshoes.com','vibramfivetoeshoes.net','vibramfivefingersshoesx.com ']
7. beatsweb=['beatsbydre.com','justlovebeats.com']
8. allweb=['vibramweb','beatsweb']
9. def serchkey(key,start):
10.         url="http://www.google.com/search?hl=en&q=%s&revid=33815775&sa=X&ei=X6CbT4GrIoOeiQfth43GAw&ved=0CIgBENUCKAY&start=%s" %(key,start)
11.         try:
12.                 opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
13.                 opener.addheaders = [('User-agent', 'Opera/9.23')]
14.                 urllib2.install_opener(opener)
15.                 req=urllib2.Request(url)
16.                 response =urllib2.urlopen(req)
17.                 content = response.read()
18.                 f=open('google','w')
19.                 f.write(content)
20.                 tiqu=os.popen("grep -ioP '(?<=<cite>).*?(?=</cite>)' google|sed -r 's/(<*\/*cite>|<\/*b>)//g'").readlines()
21.         except:
22.                 changeip()
23.         else:
24.                 for 易做图 in pinpai:
25.                                 a=1
26.                                 for shou易做图 in tiqu:
27.                                         real=shou易做图.find(易做图)
28.                                         if real>0:
29.                                                 if start==0:
30.                                                         page=1
31.                                                 elif start==10:
32.                                                         page=2
33.                                                 elif start==20:
34.                                                         page=3
35.                                                 elif start==30:
36.                                                         page=4
37.                                                 else:
38.                                                         page=5
39.                                                 lastkey=key.replace("+"," ")
40.                                      &n

补充:Web开发 , Python ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,