美文网首页程序员知了·ITIT编程
只有Google才能搜索到我的网站?!

只有Google才能搜索到我的网站?!

作者: xtutu | 来源:发表于2016-01-29 11:03 被阅读274次

前言

博客已经写了一段时间,这几天看到小伙伴在群上贴了一张图,大体是关于:在Google搜索某个关键字,可以在前几条记录里面找到他的博客内容。于是我抱着试一试的心态,在Google上搜了下自己博客里的一些关键字,效果出乎意料的好!但当我用百度,好搜,神马之类的国内搜索引擎,搜索同样的关键字,却几乎看不到任何博客信息。

Google搜索效果

搜索以下几个关键字,都可以在前面几条可以找到我的博客!

搜索"xtutu"

g20151211152712.png

搜索"游戏产品 客户端"

g20151211152919.png

搜索"游戏 转盘 算法"

g20151211153030.png

搜索"服务端架构 思考"

g20151211153107.png

搜索"c++ 添加 lua"

g20151214180240.png

手动提交sitemap

毕竟在国内,百度更加符合国人的口味,而且近一段时间百度首页也做了很多改版,比如我的关注、推荐等等,看新闻的确是方便了不少。
既然百度无法主动搜索到我的网站,只能靠我们自己把网站信息手动提交给百度了!
地址
同理,好搜,神马搜索都可以自己手动来提交网站的sitemap。

但是!!!

然后百度居然不支持hexo的sitemap!!!

解决方法

好在百度还支持主动推送,所以只好自己写脚本把网站的sitemap.xml解析成百度支持的格式,然后再发给ta。
代码如下,注意配置这块改成自己的。自己的信息可以从这里找到,就是图中的接口调用地址。


20160129102059.jpg
# !/usr/bin/env python
# coding=utf8
import urllib2
import urllib
from xml.dom import minidom

def get_nodevalue(node, index = 0):
    return node.childNodes[index].nodeValue if node else ''

# 配置信息
# 如果sitemap中的地址是xtutu.me,当设为True的时候,就会自动把地址补为www.xtutu.me
needAddWWW = False
sitemapUrl = "http://www.xtutu.me/sitemap.xml"
baiduUrl = "http://data.zz.baidu.com/urls?site=www.xtutu.me&token=xxxxxxxxxxxxxx&type=original"

# 获取并解析xml文件
linksStr = ""
req = urllib2.urlopen(sitemapUrl)
xmlVal = req.read()
doc = minidom.parseString(xmlVal)
root = doc.documentElement
urlSet = root.getElementsByTagName('url')
for node in urlSet:
    urlString = get_nodevalue(node.getElementsByTagName('loc')[0]).encode('utf-8','ignore')
    if needAddWWW:  # 判断是否需添加www字段
        urlString = urlString.replace("://", "://www.")
    linksStr = linksStr + urlString + "\n"
print linksStr

# 发送xml文件给百度
req = urllib2.urlopen(baiduUrl, linksStr)
content = req.read()
print content

raw_input("Press ENTER to exit")

输出结果

http://www.xtutu.me/search-engine-and-my-website/
http://www.xtutu.me/baidu_verify_4Lm08kj7TJ.html
http://www.xtutu.me/egret-graphics-draw-optimize/
http://www.xtutu.me/game-wheel-lottery/
http://www.xtutu.me/think-about-server/
http://www.xtutu.me/helloworld/
http://www.xtutu.me/typescript-javascript-compare/
http://www.xtutu.me/egret-source-part-mainloop/
http://www.xtutu.me/egret-source-part-render/
http://www.xtutu.me/how-to-create-a-good-game-for-client-programmer/
http://www.xtutu.me/python-script-to-upload-directory-from-windows-to-a-linux-server-achieving-one-click-deployment/
http://www.xtutu.me/the-date-object-in-js/
http://www.xtutu.me/coffeescript-javascript-compare/
http://www.xtutu.me/add-lua-support-for-cplusplus-project/
http://www.xtutu.me/categories/index.html
http://www.xtutu.me/tags/index.html
http://www.xtutu.me/egret/
http://www.xtutu.me/about/index.html
http://www.xtutu.me/404.html

{"remain":387,"success":19}

代码地址
https://github.com/xtutu/util-script

百度,我只能帮你到这里了

后记

好搜,神马在提交了sitemap之后,搜索结果的确是有了不少改善,但是还是没有google那么精准。
至于百度。。。搜索结果依旧毫无改善。
查了下资料,才发现居然是因为Github主动屏蔽了来自于BaiduSpider的请求。- -!
不过这一情况可以通过CDN(国内的很多平台都需要备案)来解决,可以参考以下这篇文章:
http://www.dozer.cc/2015/06/github-pages-and-cdn.html
目前我是把博客移到了gitcafe上。。。但是即使我做了这么多,百度依旧搜不到我的博客,看来只能慢慢等百度收录了。。。

本文同步发表在个人网站xtutu.me

相关文章

网友评论

    本文标题:只有Google才能搜索到我的网站?!

    本文链接:https://www.haomeiwen.com/subject/mayjkttx.html