百度指定行业seo市场竞争度查询工具,seo市场竞争,[Python]代码#
百度指定行业seo市场竞争度查询工具,seo市场竞争,[Python]代码#
[Python]代码
# -*- coding: utf-8 -*-from bs4 import BeautifulSoupimport urllib2,re,timekeys=["玩具","儿童玩具","少儿玩具","智力玩具","益智玩具","安全玩具"]urls={}#放排名总合#小数部分存放找到次数整数部分存放排名总数urls1={}#放排名次数urls2={}#放平均排名urls3={}#计算关键词覆盖率for key in keys: key=urllib2.quote(key)#汉字转码 html=urllib2.urlopen("http://www.baidu.com/s?word=%s" %key) soup=BeautifulSoup(html) n=1 for tables in soup.find_all("table",class_=re.compile("result"),id=re.compile("\d{1,2}")): if tables.get("mu") and not tables.find("span","g"):#百度产品 #mu="baidu.com/link?url=为百度知道baidu.com/s?tn=baidurt&rtt=1是新闻 print n, if tables.get("mu").find("link?url=")+1: print "zhidao.baidu.com" url="zhidao.baidu.com" elif tables.get("mu").find("s?tn=baidurt")+1: print "news.baidu.com" url="news.baidu.com" else: print tables.get("mu").split("http://")[1].split("/")[0] url=tables.get("mu").split("http://")[1].split("/")[0] else: print n, if tables.find("span","g").get_text().find("wenku.baidu")+1: print "wenku.baidu.com" url="wenku.baidu.com" else: print tables.find("span","g").get_text().split(" ")[2].split("/")[0] url=tables.find("span","g").get_text().split(" ")[2].split("/")[0] try: urls[url]+=n urls1[url]+=1 except: urls[url]=n urls1[url]=1 n+=1print urlsprint "\n"*3for each in urls: urls2[each]=urls[each]/urls1[each] print each print "total sum position is "+str(urls[each]) print "Ranked "+str(urls1[each])+" Keywords" print "Keywords coverage is "+str(float(urls1[each])/len(keys)*100).split(".")[0]+"%" print "average position is "+str(urls2[each]) print "\n"*4
相关内容
- 福彩3D号码预测,福彩3d预测,[Python]代码im
- 采用右递归的超简单八皇后解决,采用递归皇后,[Pyth
- 人人自动@所有好友,人人好友,[Python]代码#
- boost regex 获取 FTP 响应响应消息,boostregex,boost regex获
- Python爬取红黑联盟读书频道的图书,python读书频道,2.
- Learn Python By Practice — Utilities模块,pythonutilities,Utilit
- Google Python Class练习解答1-string1.py,python1-string1.py,stri
- Learn Python By Practice — 排序和元组,pythonpractice,排序和
- 用urllib按照百度音乐分类下载mp3,urllib百度音乐mp3,[P
- 从1到10的循环方式改进,10循环方式改进,换一种循环方
评论关闭