Back

百度SEO小工具:推送链接

发布时间: 2015-08-31 23:04:00

(更多内容,请看: 搜索引擎优化建议 http://zhanzhang.baidu.com/wiki/5) , 

  搜索引擎基础知识 http://zhanzhang.baidu.com/wiki/4)

 主动推送比 被动等待好的多.

$ cat push_to_baidu.rb 
require 'httparty'
require 'nokogiri'

root_path = 'http://siwei.me/blog/categories/--5'
site = 'http://www.siwei.me'

response = HTTParty.get root_path

urls = Nokogiri::HTML(response.body).css('article a').map { |a_link|
  "#{site}#{a_link['href']} "
}


uri = URI.parse('http://data.zz.baidu.com/urls?site=www.siwei.me&token=GREDsqR73Fu9fI??')
req = Net::HTTP::Post.new(uri.request_uri)
req.body = urls.join("\n")
req.content_type = 'text/plain'
res = Net::HTTP.start(uri.hostname, uri.port) { |http| http.request(req) }
puts res.body

Back