本帖最后由 豫瞳 于 2014-6-14 10:43 编辑
没搞出来,觉得没对劲,出来后觉得 意义不大。
因为:
因为有这效果,所以百度将抓取诊断工具有一定限额,在一定时间内只能抓取300次网页。但效果还可以扩大化。
根据测试,通过抓取诊断工具抓取的页面,其上面的链接往往可以被提取并抓取下一层的网页(但不抓取更多层)。一个页面上至少可以放500个链接,即在抓取诊断工具的限额内,可以促使至少数万页面的快速收录。
直接做好几个集合页面就够了手动提交,因为 企业网站 你能有几个页面。。。。。用不着哦。。。。
一个站长账号下 有很多 认证 网站,一个网站会分配给一个ID,
你要是写错了ID ,出现的结果就是。。。。。。。。。 你的数据 直接跑到认证的 别的网站去。。。。。。
格式就是:
wwww.seoqx.com
www.你提交的网站。。。。。。
www.你提交的网站。。。。。。
这个脚本有BUG ,能用,懒得改啦。。
- #encoding=utf-8
- import urllib2,urllib,re,string
- import cookielib,random
- import sys
- reload(sys)
- sys.setdefaultencoding('utf-8')
- URL_BAIDU_INDEX = u'http://www.baidu.com/';
- URL_BAIDU_TOKEN = 'https://passport.baidu.com/v2/api/?getapi&tpl=pp&apiver=v3&class=login';
- URL_BAIDU_LOGIN = 'https://passport.baidu.com/v2/api/?login';
- #设置用户名、密码
- username = '账号';
- password = '密码';
-
- #设置cookie,这里cookiejar可自动管理,无需手动指定
- cj = cookielib.CookieJar();
- opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj));
- urllib2.install_opener(opener);
- reqReturn = urllib2.urlopen(URL_BAIDU_INDEX);
-
- #获取token,
- tokenReturn = urllib2.urlopen(URL_BAIDU_TOKEN);
- matchVal = re.search(u'"token" : "(?P<tokenVal>.*?)"',tokenReturn.read());
- tokenVal = matchVal.group('tokenVal');
-
- #构造登录请求参数,该请求数据是通过抓包获得,对应https://passport.baidu.com/v2/api/?login请求
- postData = {
- 'username' : username,
- 'password' : password,
- 'u' : 'https://passport.baidu.com/',
- 'tpl' : 'pp',
- 'token' : tokenVal,
- 'staticpage' : 'https://passport.baidu.com/static/passpc-account/html/v3Jump.html',
- 'isPhone' : 'false',
- 'charset' : 'UTF-8',
- 'callback' : 'parent.bd__pcbs__ra48vi'
- };
- postData = urllib.urlencode(postData);
-
- #发送登录请求
- loginRequest = urllib2.Request(URL_BAIDU_LOGIN,postData);
- loginRequest.add_header('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');
- loginRequest.add_header('Accept-Encoding','gzip,deflate,sdch');
- loginRequest.add_header('Accept-Language','zh-CN,zh;q=0.8');
- loginRequest.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko');
- loginRequest.add_header('Content-Type','application/x-www-form-urlencoded');
- sendPost = urllib2.urlopen(loginRequest);
- #测试登陆
- #houtai = 'http://zhanzhang.baidu.com/crawltools/index'
- # content = urllib2.urlopen(houtai)
- #print content.getcode()#测试登陆
- #传递数据
- def post(http,url,siteid):
- login_data ={
- 'url':'%s'%url,
- 'type':'pc',#位置
- 'sid':'%s'%siteid, #获取百度给予网站从页面提取 ID
- }
- url='http://zhanzhang.baidu.com/crawltools/add?site=%s'%http
- headers={
- 'X-Request-By':'baidu.ajax',#省略也是可以的
- 'X-Requested-With':'XMLHttpRequest',
- 'Referer':'http://zhanzhang.baidu.com/crawltools/index?site=%s'%http,
- }
-
- data= urllib.urlencode(login_data)
- req=urllib2.Request(url,data,headers)
- try:
- reason=urllib2.urlopen(req)
- a=reason.read()
- reason.close()
- except Exception, e:
- print e
- def main(http):
- # ip = '220.%s.%s.%s' % (random.randint(100,200), random.randint(100,200), random.randint(100,200))
- zhanzhang = 'http://zhanzhang.baidu.com/crawltools/index?site=%s'%http
- content = urllib2.urlopen(zhanzhang).read()
- s=str(re.findall('(?<=zzSubmitRemain">)[0-9]+',content)).translate(None,string.punctuation)
- print s
- if int(s)>=1:
- siteid=str(re.findall('(?<=siteid:)"[0-9]+',content)).translate(None,string.punctuation)#提取 网站ID
- for line in open(r'c:\\1\\url.txt'):#需要提交的URL地址 网址 记得要加 HTTP://
- post(http,line.rstrip(),siteid)
- else:
- print u"没次数了"
- return
- if __name__ == '__main__':
- main(http="http://网址")
复制代码 |