发现更大的SEO世界
 找回密码
 注册
搜索
»首页»SEO培训 SEO论坛 SEO交流 帖子
发新帖
GoGo闯,不折腾不舒服斯基    

【python】批量查询360关键词指数

本帖最后由 GoGo闯 于 2014-5-28 18:34 编辑
  1. #coding:utf-8
  2. #批量查询360关键词指数

  3. import urllib  
  4. import urllib2  
  5. import re
  6. import time
  7. import linecache

  8. req = re.compile('{"query":"(.*?)","data":{.*?"week_index":([0-9]+),"month_index":([0-9]+)}}')
  9. wordindex_360 = open('360wordindex.txt','a')
  10. nu = 1


  11. for word in open('360word.txt'):
  12.         url = 'http://index.so.com/index.php?a=overviewJson&q=%s&area=全国' % urllib.quote_plus(word)  

  13.         headers = {
  14.         ......
  15.         }  

  16.         postData = {
  17.         "a":"overiewJsom",
  18.         "q":"x",
  19.         "area":"word"
  20.         }  

  21.         postData = urllib.urlencode(postData)  
  22.        
  23.         time.sleep(0.25)
  24.         #请求并发送制定的构造数据
  25.         request = urllib2.Request(url, postData, headers)  
  26.         response = urllib2.urlopen(request)  
  27.         text = response.read()  
  28.        
  29.        
  30.         y = linecache.getline(r'daili.txt',nu)
  31.         if "360指数_访问异常出错" in text:
  32.                 print "切换代理IP:"+y

  33.                 proxy_support = urllib2.ProxyHandler({'http':y})
  34.                 opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)
  35.                 urllib2.install_opener(opener)
  36.                 request = urllib2.Request(url, postData, headers)       
  37.                 text = urllib2.urlopen(request).read()                       
  38. #                time.sleep(600)
  39.                 nu = nu + 1
  40.                 continue
  41.         else:
  42.                 word_date = re.findall(req,text)       
  43.                 for x in word_date:
  44.                         data_list = list(x)
  45.                         data_str = ','.join(data_list).decode('unicode_escape').encode('utf-8').replace(',',' ') #unicode编码转中文
  46.                         wordindex_360.write(data_str+'\n')
  47.                 print data_str

  48.        
复制代码




运行结果:





ps:注意空格和tab,有时粘过去再改改缩进会有问题,改完格式化一遍

评分

参与人数 2赞同 +8 收起 理由
张伟 + 4 很给力!
ZERO + 4

查看全部评分

发表于 2014-5-27 16:10:58 |只看大图
回复 收藏
WangGaoshu,请到个人资料页面设置个人签名    

NameError: name 'data_str' is not defined
发表于 2014-5-27 17:25:47
回复 收藏
GoGo闯,不折腾不舒服斯基    

本帖最后由 GoGo闯 于 2014-5-28 10:20 编辑
WangGaoshu 发表于 2014-5-27 17:25
NameError: name 'data_str' is not defined


啊,一出验证码就没有data——str的值了
 楼主| 发表于 2014-5-27 23:15:21
回复 收藏
born,个人微信公众账号:jinan_seo请马上关注    

高大上啊!
发表于 2014-5-28 16:05:54
回复 收藏
涂丹,这就是搜索引擎    

这区分了seo的档次啊
发表于 2014-6-7 00:59:28
回复 收藏
AIR_seoqx,希望在SEO前线的乐土中,真正享受SEO的滋润。    

如果代码中写一点注释,就perfect
发表于 2014-6-8 17:37:17
回复 收藏
笑大虫威武,努力前行的屌丝男。。    

哎,好东西,得学习python     苦逼。。。
发表于 2014-6-30 21:28:30
回复 收藏
赵伟,非专业潜水员    

high big up 正想学习
发表于 2014-7-3 10:59:55
回复 收藏
,请到个人资料页面设置个人签名    

楼主  为什么我运行不了呢?望指点一二。我发现我在论坛里找的这些脚本,运行后窗口就消失了,不会有输出结果显示在哪里。这怎么回事呢?
匿名  发表于 2014-8-12 13:55:49
回复 收藏
思明,技术宅男SEO之路    QQ:176089710    


  1. for x in word_date:
  2.                    data_list = list(x)
  3.                    data_str = ','.join(data_list).decode('unicode_escape').encode('utf-8').replace(',',' ') #unicode编码转中文
  4.                    wordindex_360.write(data_str+'\n')
  5.                    print data_str
复制代码



print data_str 缩进一格就不会出现没有数据报错。
发表于 2014-8-13 09:18:45
回复 收藏
SEO小橙,请到个人资料页面设置个人签名    

请问那个省滤号的缩进错误是怎么回事呢?

QQ图片20140818131408.jpg (2.25 KB, 下载次数: 278)

QQ图片20140818131408.jpg
发表于 2014-8-18 13:15:25
回复 收藏
,请到个人资料页面设置个人签名    

回复内容已删除
匿名  发表于 2014-9-20 13:18:41
回复 收藏
快速回复 返回顶部 返回列表