阿百川 发表于 2013-4-2 14:40:15

贺新版开张,发一个自己写的获取gg搜索结果数量的代码

本帖最后由 阿百川 于 2013-4-2 14:41 编辑

#!/usr/bin/python
# -*- coding: utf-8 -*-

import urllib,urllib2,re
def sunWeb(proxy='http://g.cn:80'):
    ph = urllib2.ProxyHandler({"http":proxy,"https":proxy})
    opener = urllib2.build_opener(ph)
    opener.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0'),
                         ('Accept-Language','en-us,en;q=0.5')]
    returnopener

GETNUM = re.compile(r'<div id=.?resultStats.?>[^\d<]*([\d,]+) results?<',re.I)

def ggNum(key):
    baseurl = 'http://www.google.com/search?hl=en&pws=0&query=%s&source=ig&sky=rndy'
    ggurl = baseurl % urllib.quote_plus(key)
    html = br.open(ggurl).read()
    if 'schema.org/WebPage' not in html: 'IP Block'
    if 'Your search -' in html:return '0'
    gn = GETNUM.search(html)
    return gn.group(1) if gn else '0'

br = sunWeb()

print ggNum('site:google.com')
print ggNum('intitle:keyword')
print ggNum('"advertcn.com"')代码很简单,支持代理,默认的代理g.cn,可以自己设置

复制代码有干扰码到这:http://pastebin.com/2JP7QpDY

西瓜皮 发表于 2013-4-2 15:00:12

python啊!

rootsir 发表于 2013-4-2 16:41:49

:lolz虽然简单还是支持一下 :lol

centos 发表于 2013-4-2 17:14:07

DZ的干扰码有点操蛋

:dizzy:

yoo 发表于 2013-4-3 18:32:24

GG不允许用代码直接搜索,如果用这样的代码次数多一点,就会被GG停止,无法使用。

阿百川 发表于 2013-4-3 19:27:08

yoo 发表于 2013-4-3 18:32 static/image/common/back.gif
GG不允许用代码直接搜索,如果用这样的代码次数多一点,就会被GG停止,无法使用。 ...

每小时IP 200-300次查询,木问题

懒一点adsl换个IP,或使用代理都可以

farmer111 发表于 2013-4-12 18:33:13

阿百川 发表于 2013-4-3 19:27 static/image/common/back.gif
每小时IP 200-300次查询,木问题

懒一点adsl换个IP,或使用代理都可以

真心感谢
还有限制次数的解释
不错哦

GG限制是必须的
用代理也是必须的
页: [1]
查看完整版本: 贺新版开张,发一个自己写的获取gg搜索结果数量的代码