Skip to content

Instantly share code, notes, and snippets.

@b0n
Last active August 29, 2015 14:06
Show Gist options
  • Save b0n/c438dd80b597dcd1254d to your computer and use it in GitHub Desktop.
Save b0n/c438dd80b597dcd1254d to your computer and use it in GitHub Desktop.
Select plugin name and version from wp page or plugins
# coding: utf-8
require 'open-uri'
require 'nokogiri'
url = "http://test.localhost/abc.plugin.html"
charset = nil
html = open(url) do |f|
charset = f.charset
f.read
end
doc = Nokogiri::HTML.parse(html, nil, charset)
plugins = Array.new()
doc.xpath('//tr[@class="active"]').each do |node|
name = node.xpath('td[@class="plugin-title"]/strong/text()').to_s
ver = node.xpath('td/div[@class="active second plugin-version-author-uri"]/text()')
/^[^ ]+ (.*) \| .*$/.match(ver[0].to_s)
ver = $1
plugins.push({'name'=> name, 'ver'=> ver})
end
require 'json'
puts JSON.generate(plugins)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment